ソースを参照

Raise exception if file already exists in DirectoryStorage target

tags/v1.0
JustAnotherArchivist 1年前
コミット
a9e838adde
1個のファイルの変更4行の追加0行の削除
  1. +4
    -0
      codearchiver/storage.py

+ 4
- 0
codearchiver/storage.py ファイルの表示

@@ -45,11 +45,15 @@ class DirectoryStorage(Storage):

def put(self, filename, index = None):
self._ensure_directory()
#FIXME: Race condition
if os.path.exists((targetFilename := os.path.join(self._directory, os.path.basename(filename)))):
raise FileExistsError(f'{targetFilename} already exists')
_logger.info(f'Moving {filename} to {self._directory}')
shutil.move(filename, self._directory)
if not index:
return
indexFilename = os.path.join(self._directory, f'{filename}.codearchiver-index')
# No need to check for existence here thanks to the 'x' mode
_logger.info(f'Writing index for {filename} to {indexFilename}')
with open(indexFilename, 'x') as fp:
fp.write(index.serialise())


読み込み中…
キャンセル
保存