Merge lp:~mascha/sbackup/trunkFixFor632605 into lp:sbackup

Proposed by Martin Schaaf
Status: Merged
Merged at revision: 196
Proposed branch: lp:~mascha/sbackup/trunkFixFor632605
Merge into: lp:sbackup
Diff against target: 111 lines (+28/-7)
5 files modified
src/sbackup/ar_backend/tar.py (+3/-5)
src/sbackup/fs_backend/_fuse_utils.py (+7/-1)
src/sbackup/fs_backend/_gio_utils.py (+9/-1)
src/sbackup/util/exceptions.py (+5/-0)
src/sbackup/util/interfaces.py (+4/-0)
To merge this branch: bzr merge lp:~mascha/sbackup/trunkFixFor632605
Reviewer Review Type Date Requested Status
Jean-Peer Lorenz Approve
Martin Schaaf Pending
Review via email: mp+38763@code.launchpad.net

This proposal supersedes a proposal from 2010-10-04.

To post a comment you must log in.
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote : Posted in a previous version of this proposal

Thank you so much. I really appreciate your help.

Before merging your branch I've a few comments that need fixing though:

* don't import sys. Please use (more simple and intuitive):
...
except FileAccessError, error:
    log.error(_("message: %s" % error)

* use logger.error instead of logger.warning

* please re-raise an exception within the close_stream methods. Use the same exception in both backends. Purpose is to decide outside (i.e. when using close_stream) whether or not we want to ignore errors, how to handle them etc. This could be done by translating *some* caught errors into well defined one. Maybe it's worth to declare a new custom exception. Just have a look into 'utils.exception' at the FileAccessError section and propose one. E.g. in fuse_utils:

...
except (IOError, OSError), error:
    raise FileAccessError(_("Error while closing stream: %s") % error)

Similar for gio_utils (gio.Error and glib.Error). Just have a look at similar methods.

* please don't catch *all* exceptions. This is bad style. Catch only exceptions meaningful in the specific context. That is IOError and OSError in fuse backend and gio.Error and glib.Error in gio backend.

* catch according exception in module tar (line ~820) and log a message. I really don't like the idea of catching errors on stream closing in general.

* be sure your code complys to Python conventions: spaces instead of tabs, variable names at least 3 characters long, no camel case (I know, there are lots of not compliant LOC though I try to improve code quality whenever possible.) Use pylint if you want.

review: Needs Fixing
Revision history for this message
Martin Schaaf (mascha) wrote : Posted in a previous version of this proposal

Hej Jean-Peer,

the patch should now follow your advices. Please have a look.

Bye,
martin.

review: Needs Resubmitting
Revision history for this message
Martin Schaaf (mascha) : Posted in a previous version of this proposal
review: Abstain
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote : Posted in a previous version of this proposal

Hi Martin,
the patch looks great. Before I'll merge it into trunk I'd suggest a few changes:

1. make the warning in tar.py more verbose/descriptive e.g.
"Error (was ignored) while closing snapshot file: %s"
2. make this string translatable
3. revert the debug.error back into debug.warning (was my bad, of course it's a warning rather an error if we ignore the underlying error)
4. rename the exception FileAlreadyClosedException into FileAlreadyClosedError in order to follow Python's convention
4. in _fuse_utils: also throw a FileAlreadyClosedError and make the error message the same as in _gio_utils:
_("Error while closing stream: %s") % error (the method name isn't required since it has no value for users and is contained in the traceback)
5. make the error message here: raise FileAccessException(get_gio_errmsg(error, "Error in 'close_stream'"))
also look the same (get_gio_errmsg(error, _("Error while closing stream"))
6. add 'close_stream' to the interface class IOperations in util.interfaces

Thanks a lot.

review: Needs Fixing
lp:~mascha/sbackup/trunkFixFor632605 updated
202. By Martin Schaaf

* do not import exceptions twice

203. By Martin Schaaf

* prefix errors with module name

Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :

Thanks for your effort and contribution.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sbackup/ar_backend/tar.py'
2--- src/sbackup/ar_backend/tar.py 2010-10-03 11:47:42 +0000
3+++ src/sbackup/ar_backend/tar.py 2010-10-18 20:06:06 +0000
4@@ -35,7 +35,6 @@
5 import tempfile
6 import shutil
7 import re
8-import sys
9
10 from datetime import datetime
11
12@@ -46,7 +45,6 @@
13
14 from sbackup.util.log import LogFactory
15 from sbackup.util.structs import SBdict
16-from sbackup.util.exceptions import SBException
17 from sbackup.util import exceptions
18 from sbackup.util import constants
19 from sbackup.util import system
20@@ -1050,9 +1048,9 @@
21 n += 1
22 header += c
23 try:
24- fd.close()
25- except:
26- LogFactory.getLogger().warn("error on closing the snarfile header after reading: " + str(sys.exc_info()[1]))
27+ _FOP.close_stream(fd)
28+ except exceptions.FileAlreadyClosedError, error:
29+ log.LogFactory.getLogger().warn(_("File was already closed (ignored): %s") % error)
30
31 return header
32
33
34=== modified file 'src/sbackup/fs_backend/_fuse_utils.py'
35--- src/sbackup/fs_backend/_fuse_utils.py 2010-08-12 23:53:28 +0000
36+++ src/sbackup/fs_backend/_fuse_utils.py 2010-10-18 20:06:06 +0000
37@@ -33,7 +33,7 @@
38 from sbackup.util import interfaces
39 from sbackup.util import structs
40 from sbackup.util import pathparse
41-
42+from sbackup.util import exceptions
43
44 #TODO: move available services into FUSE plugin manager and retrieve them dynamically
45 REMOTE_SERVICE_SFTP = 101
46@@ -162,6 +162,12 @@
47 def is_dir(cls, path):
48 return local_file_utils.is_dir(path)
49
50+ @classmethod
51+ def close_stream(cls, file_desc):
52+ try:
53+ file_desc.close()
54+ except IOError, error:
55+ raise exceptions.FileAlreadyClosedError(_("Error while closing stream: %s") % error)
56
57 def get_scheme_from_service(service):
58 if not isinstance(service, types.IntType):
59
60=== modified file 'src/sbackup/fs_backend/_gio_utils.py'
61--- src/sbackup/fs_backend/_gio_utils.py 2010-10-03 15:02:59 +0000
62+++ src/sbackup/fs_backend/_gio_utils.py 2010-10-18 20:06:06 +0000
63@@ -45,7 +45,6 @@
64 from sbackup.util import system
65 from sbackup.util import log
66
67-
68 errorcodes = {
69 gio.ERROR_ALREADY_MOUNTED : exceptions.ErrorDescription(gio.ERROR_ALREADY_MOUNTED,
70 "ERROR_ALREADY_MOUNTED",
71@@ -815,6 +814,15 @@
72 _ostr.write(content)
73 _ostr.close()
74
75+ @classmethod
76+ def close_stream(cls, file_desc):
77+ try:
78+ file_desc.close()
79+ except gio.Error, error:
80+ if error.code == gio.ERROR_CLOSED:
81+ raise exceptions.FileAlreadyClosedException(_("Error while closing stream: %s") % error)
82+ else:
83+ raise exceptions.FileAccessException(get_gio_errmsg(error, _("Error while closing stream")))
84
85 def get_gio_errmsg(error, title):
86 _error_descr = errorcodes[error.code]
87
88=== modified file 'src/sbackup/util/exceptions.py'
89--- src/sbackup/util/exceptions.py 2010-08-14 00:06:35 +0000
90+++ src/sbackup/util/exceptions.py 2010-10-18 20:06:06 +0000
91@@ -163,3 +163,8 @@
92 """This Exception is thrown when remote path is not mountable.
93
94 """
95+
96+class FileAlreadyClosedError(SBException) :
97+ """This Exception is thrown when a file or stream cannot be closed because it is already closed.
98+
99+ """
100
101=== modified file 'src/sbackup/util/interfaces.py'
102--- src/sbackup/util/interfaces.py 2010-10-03 11:47:42 +0000
103+++ src/sbackup/util/interfaces.py 2010-10-18 20:06:06 +0000
104@@ -181,3 +181,7 @@
105 @classmethod
106 def is_dir(cls, path):
107 raise NotImplementedError(_get_notimplemented_msg("IOperations", "is_dir"))
108+
109+ @classmethod
110+ def close_stream(cls, file_desc):
111+ raise NotImplementedError(_get_notimplemented_msg("IOperations", "close_stream"))

Subscribers

People subscribed via source and target branches