def _commit_item(self, rev): item = rev.item metadata = {'__timestamp': rev.timestamp} metadata.update(rev) md = pickle.dumps(metadata, protocol=PICKLEPROTOCOL) rev._fs_file_meta.write(md) self._close_revision_meta(rev) self._close_revision_data(rev) data_hash = metadata[HASH_ALGORITHM] pd = self._make_path('data', data_hash) if item._fs_item_id is None: self._add_item_internally(item, revmeta=rev._fs_path_meta, revdata=rev._fs_path_data, revdata_target=pd) else: try: filesys.rename_no_overwrite(rev._fs_path_data, pd, delete_old=True) except OSError, err: if err.errno != errno.EEXIST: raise pm = self._make_path('meta', item._fs_item_id, '%d.rev' % rev.revno) try: filesys.rename_no_overwrite(rev._fs_path_meta, pm, delete_old=True) except OSError, err: if err.errno != errno.EEXIST: raise raise RevisionAlreadyExistsError("")
def _commit_item(self, rev): item = rev.item metadata = {'__timestamp': rev.timestamp} metadata.update(rev) md = pickle.dumps(metadata, protocol=PICKLEPROTOCOL) hasdata = rev._fs_file.tell() > self._revmeta_reserved_space + 4 if hasdata and len(md) > self._revmeta_reserved_space: oldrp = rev._fs_revpath oldf = rev._fs_file fd, rev._fs_revpath = tempfile.mkstemp('-rev', 'tmp-', self._path) rev._fs_file = f = os.fdopen(fd, 'wb+') f.write(struct.pack('!I', len(md) + 4)) # write metadata f.write(md) # copy already written data oldf.seek(self._revmeta_reserved_space + 4) shutil.copyfileobj(oldf, f) oldf.close() os.unlink(oldrp) else: if not hasdata: rev._fs_file.seek(0) rev._fs_file.write(struct.pack('!L', len(md) + 4)) else: rev._fs_file.seek(4) rev._fs_file.write(md) rev._fs_file.close() if item._fs_item_id is None: self._add_item_internally(item, newrev=rev._fs_revpath) else: rp = os.path.join(self._path, item._fs_item_id, 'rev.%d' % rev.revno) try: filesys.rename_no_overwrite(rev._fs_revpath, rp, delete_old=True) except OSError, err: if err.errno != errno.EEXIST: raise raise RevisionAlreadyExistsError("")
def test_special_rename_notexists(self): self.makefile(self.src, "src") filesys.rename_no_overwrite(self.src, self.dst, delete_old=True) assert not os.path.exists(self.src)
def test_win32_rename_notexists(self): self.makefile(self.src, "src") filesys.rename_no_overwrite(self.src, self.dst) dst_contents = open(self.dst).read() assert dst_contents == "src"