Skip to content

Commit d311c75

Browse files
authored
api: only create files when storing files into it
github pr#3
1 parent 2540120 commit d311c75

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/numbat/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def create(cls, path: Path | str) -> "SourcetrailDB":
194194
# Create project directory
195195
obj.project_dir = obj.path.parent
196196
obj.files_directory = Path(str(obj.path.stem) + cls.SOURCETRAIL_PROJECT_DIR)
197-
Path(obj.project_dir, obj.files_directory).mkdir(mode=0o755, exist_ok=True)
198197
# Commit change to the database so we don't ended up with a half setup DB if
199198
# an exceptions is raised before the next commit
200199
obj.commit()
@@ -1323,6 +1322,10 @@ def associate_file_to_node(
13231322
break
13241323
sha256.update(data)
13251324
hash = sha256.hexdigest()
1325+
1326+
if not self.files_directory.exists(): # Create directory on first write
1327+
self.files_directory.mkdir(mode=0o755, exist_ok=True)
1328+
13261329
file_path = f"{self.files_directory}/{hash}"
13271330
dest = f"{self.project_dir}/{file_path}"
13281331

0 commit comments

Comments
 (0)