Page MenuHomeSoftware Heritage
Paste P152

(An Untitled Masterwork)
ActivePublic

Authored by seirl on Mar 28 2017, 4:56 PM.
diff --git a/swh/objstorage/objstorage_pathslicing.py b/swh/objstorage/objstorage_pathslicing.py
index 897a5f7..5a897e8 100644
--- a/swh/objstorage/objstorage_pathslicing.py
+++ b/swh/objstorage/objstorage_pathslicing.py
@@ -37,12 +38,6 @@ def _write_obj_file(hex_obj_id, objstorage):
Yields:
a file-like object open for writing bytes.
"""
- # Get the final paths and create the directory if absent.
- dir = objstorage._obj_dir(hex_obj_id)
- if not os.path.isdir(dir):
- os.makedirs(dir, DIR_MODE, exist_ok=True)
- path = os.path.join(dir, hex_obj_id)
-
# Create a temporary file.
(tmp, tmp_path) = tempfile.mkstemp(suffix='.tmp', prefix='hex_obj_id.',
dir=dir)
@@ -54,6 +49,13 @@ def _write_obj_file(hex_obj_id, objstorage):
# Then close the temporary file and move it to the right directory.
tmp_f.close()
+
+ # Get the final paths and create the directory if absent.
+ dir = objstorage._obj_dir(hex_obj_id)
+ if not os.path.isdir(dir):
+ os.makedirs(dir, DIR_MODE, exist_ok=True)
+ path = os.path.join(dir, hex_obj_id)
+
os.chmod(tmp_path, FILE_MODE)
os.rename(tmp_path, path)