コード例 #1
0
ファイル: archive.py プロジェクト: swipswaps/attic
 def process_file(self, path, st, cache):
     safe_path = make_path_safe(path)
     # Is it a hard link?
     if st.st_nlink > 1:
         source = self.hard_links.get((st.st_ino, st.st_dev))
         if (st.st_ino, st.st_dev) in self.hard_links:
             item = self.stat_attrs(st, path)
             item.update({b'path': safe_path, b'source': source})
             self.add_item(item)
             return
         else:
             self.hard_links[st.st_ino, st.st_dev] = safe_path
     path_hash = self.key.id_hash(os.path.join(self.cwd, path).encode('utf-8', 'surrogateescape'))
     ids = cache.file_known_and_unchanged(path_hash, st)
     chunks = None
     if ids is not None:
         # Make sure all ids are available
         for id_ in ids:
             if not cache.seen_chunk(id_):
                 break
         else:
             chunks = [cache.chunk_incref(id_, self.stats) for id_ in ids]
     # Only chunkify the file if needed
     if chunks is None:
         with open(path, 'rb') as fd:
             chunks = []
             for chunk in chunkify(fd, WINDOW_SIZE, CHUNK_MASK, CHUNK_MIN, self.key.chunk_seed):
                 chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats))
         cache.memorize_file(path_hash, st, [c[0] for c in chunks])
     item = {b'path': safe_path, b'chunks': chunks}
     item.update(self.stat_attrs(st, path))
     self.stats.nfiles += 1
     self.add_item(item)
コード例 #2
0
ファイル: archive.py プロジェクト: iceqapprentice/attic
 def process_file(self, path, st, cache):
     safe_path = make_path_safe(path)
     # Is it a hard link?
     if st.st_nlink > 1:
         source = self.hard_links.get((st.st_ino, st.st_dev))
         if (st.st_ino, st.st_dev) in self.hard_links:
             item = self.stat_attrs(st, path)
             item.update({b'path': safe_path, b'source': source})
             self.add_item(item)
             return
         else:
             self.hard_links[st.st_ino, st.st_dev] = safe_path
     path_hash = self.key.id_hash(os.path.join(self.cwd, path).encode('utf-8', 'surrogateescape'))
     ids = cache.file_known_and_unchanged(path_hash, st)
     chunks = None
     if ids is not None:
         # Make sure all ids are available
         for id_ in ids:
             if not cache.seen_chunk(id_):
                 break
         else:
             chunks = [cache.chunk_incref(id_, self.stats) for id_ in ids]
     # Only chunkify the file if needed
     if chunks is None:
         with open(path, 'rb') as fd:
             chunks = []
             for chunk in chunkify(fd, WINDOW_SIZE, CHUNK_MASK, CHUNK_MIN, self.key.chunk_seed):
                 chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats))
         cache.memorize_file(path_hash, st, [c[0] for c in chunks])
     item = {b'path': safe_path, b'chunks': chunks}
     item.update(self.stat_attrs(st, path))
     self.stats.nfiles += 1
     self.add_item(item)
コード例 #3
0
ファイル: helpers.py プロジェクト: yask123/merge
 def test(self):
     self.assert_equal(make_path_safe('/foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/f/bar'), 'f/bar')
     self.assert_equal(make_path_safe('fo/bar'), 'fo/bar')
     self.assert_equal(make_path_safe('../foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('../../foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/'), '.')
     self.assert_equal(make_path_safe('/'), '.')
コード例 #4
0
ファイル: helpers.py プロジェクト: yask123/merge
 def test(self):
     self.assert_equal(make_path_safe('/foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/f/bar'), 'f/bar')
     self.assert_equal(make_path_safe('fo/bar'), 'fo/bar')
     self.assert_equal(make_path_safe('../foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('../../foo/bar'), 'foo/bar')
     self.assert_equal(make_path_safe('/'), '.')
     self.assert_equal(make_path_safe('/'), '.')
コード例 #5
0
ファイル: archive.py プロジェクト: aykit/borg
 def process_dev(self, path, st):
     item = {b'path': make_path_safe(path), b'rdev': st.st_rdev}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
     if stat.S_ISCHR(st.st_mode):
         return 'c'  # char device
     elif stat.S_ISBLK(st.st_mode):
         return 'b'  # block device
コード例 #6
0
ファイル: archive.py プロジェクト: aykit/borg
 def process_file(self, path, st, cache):
     status = None
     safe_path = make_path_safe(path)
     # Is it a hard link?
     if st.st_nlink > 1:
         source = self.hard_links.get((st.st_ino, st.st_dev))
         if (st.st_ino, st.st_dev) in self.hard_links:
             item = self.stat_attrs(st, path)
             item.update({b'path': safe_path, b'source': source})
             self.add_item(item)
             status = 'h'  # regular file, hardlink (to already seen inodes)
             return status
         else:
             self.hard_links[st.st_ino, st.st_dev] = safe_path
     path_hash = self.key.id_hash(os.path.join(self.cwd, path).encode('utf-8', 'surrogateescape'))
     ids = cache.file_known_and_unchanged(path_hash, st)
     chunks = None
     if ids is not None:
         # Make sure all ids are available
         for id_ in ids:
             if not cache.seen_chunk(id_):
                 break
         else:
             chunks = [cache.chunk_incref(id_, self.stats) for id_ in ids]
             status = 'U'  # regular file, unchanged
     else:
         status = 'A'  # regular file, added
     # Only chunkify the file if needed
     if chunks is None:
         fh = Archive._open_rb(path, st)
         with os.fdopen(fh, 'rb') as fd:
             chunks = []
             for chunk in self.chunker.chunkify(fd, fh):
                 chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats))
         cache.memorize_file(path_hash, st, [c[0] for c in chunks])
         status = status or 'M'  # regular file, modified (if not 'A' already)
     item = {b'path': safe_path, b'chunks': chunks}
     item.update(self.stat_attrs(st, path))
     self.stats.nfiles += 1
     self.add_item(item)
     return status
コード例 #7
0
ファイル: archive.py プロジェクト: iceqapprentice/attic
 def process_symlink(self, path, st):
     source = os.readlink(path)
     item = {b'path': make_path_safe(path), b'source': source}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
コード例 #8
0
ファイル: archive.py プロジェクト: iceqapprentice/attic
 def process_dev(self, path, st):
     item = {b'path': make_path_safe(path), b'rdev': st.st_rdev}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
コード例 #9
0
ファイル: archive.py プロジェクト: iceqapprentice/attic
 def process_item(self, path, st):
     item = {b'path': make_path_safe(path)}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
コード例 #10
0
ファイル: archive.py プロジェクト: aykit/borg
 def process_dir(self, path, st):
     item = {b'path': make_path_safe(path)}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
     return 'd'  # directory
コード例 #11
0
ファイル: archive.py プロジェクト: swipswaps/attic
 def process_symlink(self, path, st):
     source = os.readlink(path)
     item = {b'path': make_path_safe(path), b'source': source}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
コード例 #12
0
ファイル: archive.py プロジェクト: swipswaps/attic
 def process_dev(self, path, st):
     item = {b'path': make_path_safe(path), b'rdev': st.st_rdev}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)
コード例 #13
0
ファイル: archive.py プロジェクト: swipswaps/attic
 def process_item(self, path, st):
     item = {b'path': make_path_safe(path)}
     item.update(self.stat_attrs(st, path))
     self.add_item(item)