Skip to content

Instantly share code, notes, and snippets.

@cclecle
Created January 29, 2025 22:20
Show Gist options
  • Select an option

  • Save cclecle/b796d84459258fd11a0dfc3bc88bb663 to your computer and use it in GitHub Desktop.

Select an option

Save cclecle/b796d84459258fd11a0dfc3bc88bb663 to your computer and use it in GitHub Desktop.
Fix gluster duplicated files
#!/usr/bin/env python3
import sys
import os
import glob
from pathlib import Path
import shutil
import tempfile
def fix_file(fpath):
fname = os.path.basename(fpath)
fpath = Path(fpath)
with tempfile.TemporaryDirectory() as tmpdir:
shutil.move(fpath,Path(tmpdir) / fname)
shutil.move(Path(tmpdir) / fname,fpath)
if __name__ == '__main__':
if len(sys.argv) != 2:
raise Exception("ERR: arg 1 must be storage path.")
if not os.path.exists(sys.argv[1]):
raise Exception("ERR: given path does not exists.")
memorized = set()
for filename in glob.iglob(sys.argv[1] + '**/*', recursive=True):
if filename not in memorized:
memorized.add(filename)
else:
print(f"Fixing duplicate file ! ({filename})")
fix_file(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment