int
The number of faces that have been renamed
if not filename_mappings:
return 0
rename_count = 0
conflicts = []
for src, dst in tqdm(filename_mappings, desc="Renaming Faces"):
old = os.path.join(self._faces.folder, src)
new = os.path.join(self._faces.folder, dst)
if os.path.exists(new):
// Interim add .tmp extension to files that will cause a rename conflict, to
// process afterwards
logger.debug("interim renaming file to avoid conflict: (src: "%s", dst: "%s")",
src, dst)
new = new + ".tmp"
conflicts.append(new)
logger.verbose("Renaming "%s" to "%s"", old, new)
os.rename(old, new)
rename_count += 1
if conflicts:
for old in tqdm(conflicts, desc="Renaming Faces"):
new = old[:-4] // Remove .tmp extension
if os.path.exists(new):
// This should only be running on faces. If there is still a conflict
// then the user has done something stupid, so we will delete the file and
// replace. They can always re-extract :/
os.remove(new)
logger.verbose("Renaming "%s" to "%s"", old, new)
os.rename(old, new)
return rename_count