Skip to content

Commit 7db9b3e

Browse files
spoorccben-edna
authored andcommitted
Only remove fetched files
1 parent 9b2f2e9 commit 7db9b3e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

dfetch/project/vcs.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import pathlib
66
from abc import ABC, abstractmethod
7+
from contextlib import suppress
78
from typing import Iterable, List, Optional, Sequence, Tuple
89

910
from halo import Halo
@@ -116,7 +117,20 @@ def update(self, force: bool = False) -> None:
116117

117118
if os.path.exists(self.local_path):
118119
logger.debug(f"Clearing destination {self.local_path}")
119-
safe_rm(self.local_path)
120+
121+
with suppress(TypeError):
122+
metadata_files = Metadata.from_file(self.__metadata.path).files
123+
124+
if metadata_files:
125+
for file in metadata_files:
126+
full_path = os.path.join(self.local_path, file.path)
127+
safe_rm(full_path)
128+
parent_dir = os.path.dirname(full_path)
129+
# remove parent if empty
130+
if not os.listdir(parent_dir):
131+
safe_rm(parent_dir)
132+
else:
133+
safe_rm(self.local_path)
120134

121135
with Halo(
122136
text=f"Fetching {self.__project.name} {to_fetch}",

0 commit comments

Comments
 (0)