buglvl = atoi(os.environ.get('BUP_DEBUG', 0))
-# If the platform doesn't have fdatasync (OS X), fall back to fsync.
-try:
- fdatasync = os.fdatasync
-except AttributeError:
- fdatasync = os.fsync
+if sys.platform.startswith('darwin'):
+ # Apparently fsync on OS X doesn't guarantee to sync all the way down
+ import fcntl
+ fdatasync = lambda fd : fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
+else: # If the platform doesn't have fdatasync, fall back to fsync
+ try:
+ fdatasync = os.fdatasync
+ except AttributeError:
+ fdatasync = os.fsync
# Write (blockingly) to sockets that may or may not be in blocking mode.
yield readpipe(command + sub_args, preexec_fn=preexec_fn)
-def realpath(p):
- """Get the absolute path of a file.
+def resolve_parent(p):
+ """Return the absolute path of a file without following any final symlink.
Behaves like os.path.realpath, but doesn't follow a symlink for the last
element. (ie. if 'p' itself is a symlink, this one won't follow it, but it
for flag in options:
(option, parameter) = flag
if option == '--exclude':
- excluded_paths.append(realpath(parameter))
+ excluded_paths.append(resolve_parent(parameter))
elif option == '--exclude-from':
try:
- f = open(realpath(parameter))
+ f = open(resolve_parent(parameter))
except IOError as e:
raise fatal("couldn't read %s" % parameter)
for exclude_path in f.readlines():
# FIXME: perhaps this should be rstrip('\n')
- exclude_path = realpath(exclude_path.strip())
+ exclude_path = resolve_parent(exclude_path.strip())
if exclude_path:
excluded_paths.append(exclude_path)
return sorted(frozenset(excluded_paths))
fatal('invalid --exclude-rx pattern (%s): %s' % (parameter, ex))
elif option == '--exclude-rx-from':
try:
- f = open(realpath(parameter))
+ f = open(resolve_parent(parameter))
except IOError as e:
raise fatal("couldn't read %s" % parameter)
for pattern in f.readlines():