Commit 4ed38185 authored by ben's avatar ben

Added errno stuff instead of raw numbers, and now behavior of

destructive_stepping.init_dir depends on change_mirror_perms, which
depends on whether you are running as root or not.


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@92 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 14c49287
......@@ -77,16 +77,15 @@ class DSRPath(RPath):
def set_init_perms(self, source):
"""If necessary, change permissions to ensure access"""
if self.isreg() and not self.readable():
if not source or Globals.change_source_perms and self.isowner():
if (source and Globals.change_source_perms or
not source and Globals.change_mirror_perms):
self.chmod_bypass(0400)
else: self.warn("No read permissions")
elif self.isdir():
if source and (not self.readable() or not self.executable()):
if Globals.change_source_perms and self.isowner():
if source and Globals.change_source_perms:
if not self.readable() or not self.executable():
self.chmod_bypass(0500)
else: self.warn("No read or exec permission")
elif not source and not self.hasfullperms():
self.chmod_bypass(0700)
elif not source and Globals.change_mirror_perms:
if not self.hasfullperms(): self.chmod_bypass(0700)
def warn(self, err):
Log("Received error '%s' when dealing with file %s, skipping..."
......
......@@ -14,6 +14,6 @@
# bugs or have any suggestions.
from __future__ import nested_scopes, generators
import os, stat, time, sys, getopt, re, cPickle, types, shutil, sha, marshal, traceback, popen2, tempfile, gzip, UserList
import os, stat, time, sys, getopt, re, cPickle, types, shutil, sha, marshal, traceback, popen2, tempfile, gzip, UserList, errno
......@@ -268,19 +268,16 @@ class HLDestinationStruct:
def check_skip_error(cls, thunk, dsrp):
"""Run thunk, catch certain errors skip files"""
try: return thunk()
except (IOError, OSError, SkipFileException, DSRPPermError,
except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException), exp:
Log.exception()
if (not isinstance(exp, IOError) or
(isinstance(exp, IOError) and
(exp[0] in [2, # Means that a file is missing
5, # Reported by docv (see list)
13, # Permission denied IOError
20, # Means a directory changed to non-dir
26, # Requested by Campbell (see list) -
# happens on some NT systems
36] # filename too long
))):
if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exp[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY',
'EIO', # reported by docv
'ETXTBSY' # reported by Campbell on some NT system
])):
Log("Skipping file because of error after %s" %
(dsrp and dsrp.index,), 2)
return None
......
......@@ -199,19 +199,16 @@ class Robust:
"""
try: return init_thunk()
except (IOError, OSError, SkipFileException, DSRPPermError,
except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException), exc:
Log.exception()
if (not isinstance(exc, IOError) or
(isinstance(exc, IOError) and
(exp[0] in [2, # Means that a file is missing
5, # Reported by docv (see list)
13, # Permission denied IOError
20, # Means a directory changed to non-dir
26, # Requested by Campbell (see list) -
# happens on some NT systems
36] # filename too long
))):
if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exp[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY',
'EIO', # reported by docv
'ETXTBSY' # reported by Campbell on some NT system
])):
return error_thunk(exc)
else: raise
......
......@@ -77,16 +77,15 @@ class DSRPath(RPath):
def set_init_perms(self, source):
"""If necessary, change permissions to ensure access"""
if self.isreg() and not self.readable():
if not source or Globals.change_source_perms and self.isowner():
if (source and Globals.change_source_perms or
not source and Globals.change_mirror_perms):
self.chmod_bypass(0400)
else: self.warn("No read permissions")
elif self.isdir():
if source and (not self.readable() or not self.executable()):
if Globals.change_source_perms and self.isowner():
if source and Globals.change_source_perms:
if not self.readable() or not self.executable():
self.chmod_bypass(0500)
else: self.warn("No read or exec permission")
elif not source and not self.hasfullperms():
self.chmod_bypass(0700)
elif not source and Globals.change_mirror_perms:
if not self.hasfullperms(): self.chmod_bypass(0700)
def warn(self, err):
Log("Received error '%s' when dealing with file %s, skipping..."
......
......@@ -35,8 +35,10 @@ class Globals:
# If true, change the permissions of unwriteable mirror files
# (such as directories) so that they can be written, and then
# change them back.
change_mirror_perms = 1
# change them back. This defaults to 1 just in case the process
# is not running as root (root doesn't need to change
# permissions).
change_mirror_perms = (process_uid != 0)
# If true, temporarily change permissions of unreadable files in
# the source directory to make sure we can read all files.
......
......@@ -14,6 +14,6 @@
# bugs or have any suggestions.
from __future__ import nested_scopes, generators
import os, stat, time, sys, getopt, re, cPickle, types, shutil, sha, marshal, traceback, popen2, tempfile, gzip, UserList
import os, stat, time, sys, getopt, re, cPickle, types, shutil, sha, marshal, traceback, popen2, tempfile, gzip, UserList, errno
......@@ -268,19 +268,16 @@ class HLDestinationStruct:
def check_skip_error(cls, thunk, dsrp):
"""Run thunk, catch certain errors skip files"""
try: return thunk()
except (IOError, OSError, SkipFileException, DSRPPermError,
except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException), exp:
Log.exception()
if (not isinstance(exp, IOError) or
(isinstance(exp, IOError) and
(exp[0] in [2, # Means that a file is missing
5, # Reported by docv (see list)
13, # Permission denied IOError
20, # Means a directory changed to non-dir
26, # Requested by Campbell (see list) -
# happens on some NT systems
36] # filename too long
))):
if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exp[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY',
'EIO', # reported by docv
'ETXTBSY' # reported by Campbell on some NT system
])):
Log("Skipping file because of error after %s" %
(dsrp and dsrp.index,), 2)
return None
......
......@@ -199,19 +199,16 @@ class Robust:
"""
try: return init_thunk()
except (IOError, OSError, SkipFileException, DSRPPermError,
except (EnvironmentError, SkipFileException, DSRPPermError,
RPathException), exc:
Log.exception()
if (not isinstance(exc, IOError) or
(isinstance(exc, IOError) and
(exp[0] in [2, # Means that a file is missing
5, # Reported by docv (see list)
13, # Permission denied IOError
20, # Means a directory changed to non-dir
26, # Requested by Campbell (see list) -
# happens on some NT systems
36] # filename too long
))):
if (not isinstance(exc, EnvironmentError) or
(errno.errorcode[exp[0]] in
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY',
'EIO', # reported by docv
'ETXTBSY' # reported by Campbell on some NT system
])):
return error_thunk(exc)
else: raise
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment