1
# Copyright 2002 Ben Escoto
3
# This file is part of duplicity.
5
# duplicity is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA
8
# 02139, USA; either version 2 of the License, or (at your option) any
9
# later version; incorporated herein by reference.
12
import librsync, errno, log, path
16
def check_common_error(error_handler, function, args = ()):
17
"""Apply function to args, if error, run error_handler on exception
19
This only catches certain exceptions which seem innocent
23
try: return function(*args)
24
#except (EnvironmentError, SkipFileException, DSRPPermError,
25
# RPathException, Rdiff.RdiffException,
26
# librsync.librsyncError, C.UnknownFileTypeError), exc:
27
# TracebackArchive.add()
28
except (EnvironmentError, librsync.librsyncError, path.PathException), exc:
29
if (not isinstance(exc, EnvironmentError) or
30
(errno.errorcode[exc[0]] in
31
['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST',
32
'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY',
33
'EIO', 'ETXTBSY', 'ESRCH', 'EINVAL'])):
35
if error_handler: return error_handler(exc, *args)
41
"""Like path.listdir() but return [] if error, and sort results"""
42
def error_handler(exc):
43
log.Log("Error listing directory %s" % path.name, 2)
45
dir_listing = check_common_error(error_handler, path.listdir)