Don't use f before it's initialized.
Narrow the catch to open(), and only catch IOException.
Call Options.fatal() when there's an error (as does
helpers.parse_date_or_fatal()).
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
if len(extra) != 1:
o.fatal("exactly one filename expected")
-excluded_paths = drecurse.parse_excludes(flags)
+excluded_paths = parse_excludes(flags, o.fatal)
it = drecurse.recursive_dirlist(extra, opt.xdev, excluded_paths=excluded_paths)
if opt.profile:
log('clear: clearing index.\n')
clear_index(indexfile)
-excluded_paths = drecurse.parse_excludes(flags)
-
+excluded_paths = parse_excludes(flags, o.fatal)
paths = index.reduce_paths(extra)
if opt.update:
except:
pass
raise
-
-def parse_excludes(flags):
- excluded_paths = []
-
- for flag in flags:
- (option, parameter) = flag
- if option == '--exclude':
- excluded_paths.append(realpath(parameter))
-
- if option == '--exclude-from':
- try:
- try:
- f = open(realpath(parameter))
- for exclude_path in f.readlines():
- excluded_paths.append(realpath(exclude_path.strip()))
- except Error, e:
- log("warning: couldn't read %s\n" % parameter)
- finally:
- f.close()
-
- return excluded_paths
-
return date
+def parse_excludes(options, fatal):
+ """Traverse the options and extract all excludes, or call Option.fatal()."""
+ excluded_paths = []
+
+ for flag in options:
+ (option, parameter) = flag
+ if option == '--exclude':
+ excluded_paths.append(realpath(parameter))
+ elif option == '--exclude-from':
+ try:
+ f = open(realpath(parameter))
+ except IOError, e:
+ raise fatal("couldn't read %s" % parameter)
+ for exclude_path in f.readlines():
+ excluded_paths.append(realpath(exclude_path.strip()))
+ return excluded_paths
+
+
# FIXME: Carefully consider the use of functions (os.path.*, etc.)
# that resolve against the current filesystem in the strip/graft
# functions for example, but elsewhere as well. I suspect bup's not
D=bupdata.tmp
rm -rf $D
mkdir $D
+WVFAIL bup index --exclude-from $D/cannot-exist $D
WVPASSEQ "$(bup index --check -p)" ""
WVPASSEQ "$(bup index --check -p $D)" ""
WVFAIL [ -e $D.fake ]