Procházet zdrojové kódy

Raise exception if file already exists in DirectoryStorage target

tags/v1.0
JustAnotherArchivist před 1 rokem
rodič
revize
a9e838adde
1 změnil soubory, kde provedl 4 přidání a 0 odebrání
  1. +4
    -0
      codearchiver/storage.py

+ 4
- 0
codearchiver/storage.py Zobrazit soubor

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


Načítá se…
Zrušit
Uložit