diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py
index 866045f..536a32a 100644
--- a/lib/bup/drecurse.py
+++ b/lib/bup/drecurse.py
@@ -73,7 +73,13 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
excluded_paths=excluded_paths):
yield i
os.chdir('..')
- yield (prepend + name, pst)
+ else:
+ if excluded_paths:
+ if os.path.normpath(prepend+name) in excluded_paths:
+ debug1('Skipping %r: excluded.\n' % (prepend+name))
+ continue
+
+ yield (prepend+name, pst)
def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
--
1.7.9.2
Signed-off-by: Jakob Matthes <jakob....@googlemail.com>
---
lib/bup/drecurse.py | 14 ++++++--------
lib/bup/helpers.py | 9 +++++++++
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py
index 536a32a..66efd47 100644
--- a/lib/bup/drecurse.py
+++ b/lib/bup/drecurse.py
@@ -59,10 +59,9 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
if os.path.normpath(prepend+name) == bup_dir:
debug1('Skipping BUP_DIR.\n')
continue
- if excluded_paths:
- if os.path.normpath(prepend+name) in excluded_paths:
- debug1('Skipping %r: excluded.\n' % (prepend+name))
- continue
+ if path_in(os.path.normpath(prepend+name), excluded_paths):
+ debug1('Skipping %r: excluded.\n' % (prepend+name))
+ continue
try:
OsFile(name).fchdir()
except OSError, e:
@@ -74,10 +73,9 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
yield i
os.chdir('..')
else:
- if excluded_paths:
- if os.path.normpath(prepend+name) in excluded_paths:
- debug1('Skipping %r: excluded.\n' % (prepend+name))
- continue
+ if path_in(os.path.normpath(prepend+name), excluded_paths):
+ debug1('Skipping %r: excluded.\n' % (prepend+name))
+ continue
yield (prepend+name, pst)
diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py
index d9d177c..770875e 100644
--- a/lib/bup/helpers.py
+++ b/lib/bup/helpers.py
@@ -197,6 +197,15 @@ def realpath(p):
#log('realpathing:%r,%r\n' % (p, out))
return out
+def path_in(p, paths):
+ """Check if a given path is contained in a list of paths.
+
+ The list 'paths' can be None in which case it returns False."""
+ if paths == None:
+ return False
+ else:
+ return p in paths
+
def detect_fakeroot():
"Return True if we appear to be running under fakeroot."
--
1.7.9.2
Wrap f.close() in a try...except statement to avoid UnboundLocalError.
Maybe the nesting can be reduced without losing Python 2.4 compatibility
or missing exception cases.
Signed-off-by: Jakob Matthes <jakob....@googlemail.com>
---
lib/bup/drecurse.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py
index 66efd47..6036e84 100644
--- a/lib/bup/drecurse.py
+++ b/lib/bup/drecurse.py
@@ -135,10 +135,14 @@ def parse_excludes(flags):
f = open(realpath(parameter))
for exclude_path in f.readlines():
excluded_paths.append(realpath(exclude_path.strip()))
- except Error, e:
+ except Exception, e:
log("warning: couldn't read %s\n" % parameter)
finally:
- f.close()
+ try:
+ f.close()
+ except Exception, e:
+ pass
+
return excluded_paths
--
1.7.9.2
This was just mentioned in a pull request on github:
https://github.com/apenwarr/bup/pull/12
Alex suggests the same fix as the above.
I traced the history of this line, and it was added in commit
a1d5ae13d57, and then moved around until it was in drecurse.py.
The line was initially in index-cmd.py, but the Error class has been in
a library for quite a while.
The problem I see with this change is if realpath() throws an unexpected
exception, it'll just be grabbed by the above and logged on the screen
as a warning (which you proabably won't see if you're not attached to a
tty..)
Zoran: Was there a reason to catch "Error" in particular?
From the looks of it, the try/catch is there for the call to open(), so
shouldn't we change that catch for something more specific like
IOError[1]? Or is there something that can happen inside realpath() ?
[1]: http://docs.python.org/library/functions.html#open
--
Gabriel Filion
I haven't seen in the documentation[1] that f.close() can send an
exception. Why is this part necessary? Are there some undocumented cases
where it raises an exception?
[1]: http://docs.python.org/library/stdtypes.html#file.close
--
Gabriel Filion
Just by reading, this commit looks good to me. I'll try and test this
out soon.
Jakob, can you come up a test that verifies that a normal file is
excluded when specified in --exclude ?
--
Gabriel Filion
It looks syntactically valid, but it actually adds code and makes it a
bit tougher to read.. If the comparison is used in more places, we can
do this modification, but I don't think it's useful for just two occurences.
On 12-02-26 06:36 PM, Jakob Matthes wrote:
--
Gabriel Filion