Skip to content

Commit 0139077

Browse files
author
Tomas Babej
committed
mapper: Gate the file renaming behaviour behind rename=True
1 parent e787127 commit 0139077

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

datafiles/mapper.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,21 @@ def save(self, *, include_default_values: Trilean = None, _log=True) -> None:
266266
self._root.save(include_default_values=include_default_values, _log=_log)
267267
return
268268

269-
# Determine whether the attributes that are involved in the path were changed
269+
# Determine whether the expected filepath of the file has changed (which
270+
# happens as a result of modifying attributes that compose the filename).
271+
# Note that this behaviour is gated behind rename=True flag.
270272
file_rename_required = False
271273
original_path = self.path
272-
with hooks.disabled(): # hooks have to be disabled to prevent infinite loop
273-
if "path" in self.__dict__:
274-
del self.__dict__["path"] # invalidate the cached property
274+
print(f"The self._rename is set to {self._rename}")
275275

276-
# This call of self.path updates the value since the cache is invalidated
277-
if self.path != original_path:
278-
file_rename_required = True
276+
if self._rename:
277+
with hooks.disabled(): # hooks have to be disabled to prevent infinite loop
278+
if "path" in self.__dict__:
279+
del self.__dict__["path"] # invalidate the cached property
280+
281+
# This call of self.path updates the value since the cache is invalidated
282+
if self.path != original_path:
283+
file_rename_required = True
279284

280285
if self.path:
281286
if self.exists and self._frozen:
@@ -292,7 +297,7 @@ def save(self, *, include_default_values: Trilean = None, _log=True) -> None:
292297
text = self._get_text(include_default_values=include_default_values)
293298

294299
write(self.path, text, display=True)
295-
if file_rename_required:
300+
if self._rename and file_rename_required:
296301
remove(original_path)
297302

298303
self.modified = False

0 commit comments

Comments
 (0)