浏览代码

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())


正在加载...
取消
保存