summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-05-20 18:43:15 +0000
committerben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-05-20 18:43:15 +0000
commit1f4e957cd505f5cd3bcb6902e266b5bad6b17209 (patch)
tree60ed0b9da43cb0c4b386b3ec091ba20c87eaabf0
parente90980098d2ae3458a56b19d12805f62def8f8d6 (diff)
downloadrdiff-backup-1f4e957cd505f5cd3bcb6902e266b5bad6b17209.tar.gz
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/trunk@92 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
-rw-r--r--rdiff-backup/rdiff_backup/destructive_stepping.py13
-rw-r--r--rdiff-backup/rdiff_backup/header.py2
-rw-r--r--rdiff-backup/rdiff_backup/highlevel.py19
-rw-r--r--rdiff-backup/rdiff_backup/robust.py19
-rw-r--r--rdiff-backup/src/destructive_stepping.py13
-rw-r--r--rdiff-backup/src/globals.py6
-rw-r--r--rdiff-backup/src/header.py2
-rw-r--r--rdiff-backup/src/highlevel.py19
-rw-r--r--rdiff-backup/src/robust.py19
9 files changed, 50 insertions, 62 deletions
diff --git a/rdiff-backup/rdiff_backup/destructive_stepping.py b/rdiff-backup/rdiff_backup/destructive_stepping.py
index 0d0d529..f5d9cc3 100644
--- a/rdiff-backup/rdiff_backup/destructive_stepping.py
+++ b/rdiff-backup/rdiff_backup/destructive_stepping.py
@@ -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..."
diff --git a/rdiff-backup/rdiff_backup/header.py b/rdiff-backup/rdiff_backup/header.py
index 020a63f..71ca7d2 100644
--- a/rdiff-backup/rdiff_backup/header.py
+++ b/rdiff-backup/rdiff_backup/header.py
@@ -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
diff --git a/rdiff-backup/rdiff_backup/highlevel.py b/rdiff-backup/rdiff_backup/highlevel.py
index d3b6b74..36ac997 100644
--- a/rdiff-backup/rdiff_backup/highlevel.py
+++ b/rdiff-backup/rdiff_backup/highlevel.py
@@ -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
diff --git a/rdiff-backup/rdiff_backup/robust.py b/rdiff-backup/rdiff_backup/robust.py
index a0f6691..a5b1056 100644
--- a/rdiff-backup/rdiff_backup/robust.py
+++ b/rdiff-backup/rdiff_backup/robust.py
@@ -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
diff --git a/rdiff-backup/src/destructive_stepping.py b/rdiff-backup/src/destructive_stepping.py
index 0d0d529..f5d9cc3 100644
--- a/rdiff-backup/src/destructive_stepping.py
+++ b/rdiff-backup/src/destructive_stepping.py
@@ -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..."
diff --git a/rdiff-backup/src/globals.py b/rdiff-backup/src/globals.py
index 508d0ed..7d62733 100644
--- a/rdiff-backup/src/globals.py
+++ b/rdiff-backup/src/globals.py
@@ -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.
diff --git a/rdiff-backup/src/header.py b/rdiff-backup/src/header.py
index 020a63f..71ca7d2 100644
--- a/rdiff-backup/src/header.py
+++ b/rdiff-backup/src/header.py
@@ -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
diff --git a/rdiff-backup/src/highlevel.py b/rdiff-backup/src/highlevel.py
index d3b6b74..36ac997 100644
--- a/rdiff-backup/src/highlevel.py
+++ b/rdiff-backup/src/highlevel.py
@@ -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
diff --git a/rdiff-backup/src/robust.py b/rdiff-backup/src/robust.py
index a0f6691..a5b1056 100644
--- a/rdiff-backup/src/robust.py
+++ b/rdiff-backup/src/robust.py
@@ -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