Преглед на файлове

recover_segment(): don't assume we have an fd for segment

Suggested by @ThomasWaldmann.  Avoiding a complex assumption
should make the code easier to understand and maintain.

(Technically we do have an fd for the segment, because
the only caller opens the segment and checks it before
calling for repair.)
Alan Jenkins преди 9 години
родител
ревизия
04887439a0
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  1. 3 1
      attic/repository.py

+ 3 - 1
attic/repository.py

@@ -515,7 +515,9 @@ class LoggedIO(object):
             header = fd.read(self.header_fmt.size)
             header = fd.read(self.header_fmt.size)
 
 
     def recover_segment(self, segment, filename):
     def recover_segment(self, segment, filename):
-        self.fds.pop(segment).close()
+        fd = self.fds.pop(segment)
+        if fd is not None:
+            fd.close()
         # FIXME: save a copy of the original file
         # FIXME: save a copy of the original file
         with open(filename, 'rb') as fd:
         with open(filename, 'rb') as fd:
             data = memoryview(fd.read())
             data = memoryview(fd.read())