Skip to content

Commit 635cf97

Browse files
committed
Only remove fetched files
1 parent 45596a5 commit 635cf97

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
@@ -109,7 +110,20 @@ def update(self, force: bool = False) -> None:
109110

110111
if os.path.exists(self.local_path):
111112
logger.debug(f"Clearing destination {self.local_path}")
112-
safe_rm(self.local_path)
113+
114+
with suppress(TypeError):
115+
metadata_files = Metadata.from_file(self.__metadata.path).files
116+
117+
if metadata_files:
118+
for file in metadata_files:
119+
full_path = os.path.join(self.local_path, file.path)
120+
safe_rm(full_path)
121+
parent_dir = os.path.dirname(full_path)
122+
# remove parent if empty
123+
if not os.listdir(parent_dir):
124+
safe_rm(parent_dir)
125+
else:
126+
safe_rm(self.local_path)
113127

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

0 commit comments

Comments
 (0)