]> git.0d.be Git - django-panik-nonstop.git/commitdiff
raise errors when soma directory is not available
authorFrédéric Péters <fpeters@0d.be>
Fri, 24 Jan 2020 06:29:28 +0000 (07:29 +0100)
committerFrédéric Péters <fpeters@0d.be>
Fri, 24 Jan 2020 06:29:28 +0000 (07:29 +0100)
nonstop/utils.py

index 9941d795343dd1cfab450f14c7713465eeaacc8f..9a278f30e310088511a66338d6d03aeff8aa425b 100644 (file)
@@ -69,12 +69,20 @@ def add_diffusion(diffusion, **kwargs):
         diffusion_path = get_diffusion_file_path(diffusion)
 
         # copy file
-        if os.path.exists(LOCAL_BASE_PATH):
-            if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
-                raise DuplicateDiffusionSlot()
-            os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
+        if not os.path.exists(LOCAL_BASE_PATH):
+            raise SomaException('soma directory is not available')
+        if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
+            raise DuplicateDiffusionSlot()
+        os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
+        try:
             shutil.copyfile(soundfile.file.path,
                 os.path.join(LOCAL_BASE_PATH, diffusion_path, os.path.basename(soundfile.file.path)))
+        except IOError:
+            try:
+                os.rmdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
+            except IOError:
+                pass
+            raise SomaException('error copying file to soma')
 
         context['diffusion_path'] = diffusion_path
         # end should be a bit before the real end of file so the same file doesn't