Esempio n. 1
0
 def _queue_file(self, source, filename=None):
     try:
         src_path = os.path.realpath(source)
     except Exception:
         raise errors.AssertionError("{} not a file path".format(source))
     try:
         path_stat = os.stat(src_path)
     except OSError as stat_error:
         path_stat = None
     super(ResumableCollectionWriter, self)._queue_file(source, filename)
     fd_stat = os.fstat(self._queued_file.fileno())
     if not S_ISREG(fd_stat.st_mode):
         # We won't be able to resume from this cache anyway, so don't
         # worry about further checks.
         self._dependencies[source] = tuple(fd_stat)
     elif path_stat is None:
         raise errors.AssertionError("could not stat {}: {}".format(
             source, stat_error))
     elif path_stat.st_ino != fd_stat.st_ino:
         raise errors.AssertionError(
             "{} changed between open and stat calls".format(source))
     else:
         self._dependencies[src_path] = tuple(fd_stat)
Esempio n. 2
0
 def finish_current_file(self):
     if self._current_file_name == None:
         if self._current_file_pos == self._current_stream_length:
             return
         raise errors.AssertionError(
             "Cannot finish an unnamed file " +
             "(%d bytes at offset %d in '%s' stream)" %
             (self._current_stream_length - self._current_file_pos,
              self._current_file_pos, self._current_stream_name))
     self._current_stream_files += [[
         self._current_file_pos,
         self._current_stream_length - self._current_file_pos,
         self._current_file_name
     ]]
     self._current_file_pos = self._current_stream_length
Esempio n. 3
0
 def finish_current_stream(self):
     self.finish_current_file()
     self.flush_data()
     if len(self._current_stream_files) == 0:
         pass
     elif self._current_stream_name == None:
         raise errors.AssertionError(
             "Cannot finish an unnamed stream (%d bytes in %d files)" %
             (self._current_stream_length, len(self._current_stream_files)))
     else:
         if len(self._current_stream_locators) == 0:
             self._current_stream_locators += [config.EMPTY_BLOCK_LOCATOR]
         self._finished_streams += [[
             self._current_stream_name, self._current_stream_locators,
             self._current_stream_files
         ]]
     self._current_stream_files = []
     self._current_stream_length = 0
     self._current_stream_locators = []
     self._current_stream_name = None
     self._current_file_pos = 0
     self._current_file_name = None
Esempio n. 4
0
 def set_current_stream_name(self, newstreamname):
     if re.search(r'[\t\n]', newstreamname):
         raise errors.AssertionError(
             "Manifest stream names cannot contain whitespace")
     self._current_stream_name = '.' if newstreamname == '' else newstreamname
Esempio n. 5
0
 def set_current_file_name(self, newfilename):
     if re.search(r'[\t\n]', newfilename):
         raise errors.AssertionError(
             "Manifest filenames cannot contain whitespace: %s" %
             newfilename)
     self._current_file_name = newfilename
Esempio n. 6
0
 def write(self, data):
     if self._queued_file is None:
         raise errors.AssertionError(
             "resumable writer can't accept unsourced data")
     return super(ResumableCollectionWriter, self).write(data)