diff --git a/buffer/__init__.py b/buffer/__init__.py index bca58b3..bd9ce6e 100644 --- a/buffer/__init__.py +++ b/buffer/__init__.py @@ -659,8 +659,10 @@ class FileBuffer(Buffer): if self.changed_on_disk(): raise Exception, "oh no! %r has changed on-disk!" % self.path - temp_path = self._temp_path() - shutil.copyfile(self.path, temp_path) + exists = os.path.exists(self.path) + if exists: + temp_path = self._temp_path() + shutil.copyfile(self.path, temp_path) try: data = self.make_string() @@ -672,12 +674,12 @@ class FileBuffer(Buffer): f2.write(self.bytemark + data) f2.close() except: - shutil.copyfile(temp_path, self.path) + if exists: shutil.copyfile(temp_path, self.path) else: self.store_checksum(data) self.modified = False finally: - os.unlink(temp_path) + if exists: os.unlink(temp_path) def save_as(self, path): self.path = path self.save()