Skip to content

Instantly share code, notes, and snippets.

@aravindavk
Created December 10, 2015 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aravindavk/5307489f68cbcfb37d3d to your computer and use it in GitHub Desktop.
Save aravindavk/5307489f68cbcfb37d3d to your computer and use it in GitHub Desktop.
import uuid
import xattr
import os
from hashlib import md5
import sys
IGNORE_DIRS = [".glusterfs", ".trashcan"]
PFX = "user.pgfid"
def crawl(brick_path, path, ignore_dirs=[]):
if path in ignore_dirs:
return
pgfid = str(uuid.UUID(bytes=xattr.get(path, "trusted.gfid",
nofollow=True)))
# pgfid = str(uuid.UUID(bytes=xattr.get(path, "glusterfs.gfid",
# nofollow=True)))
files = os.listdir(path)
for f in files:
p = os.path.join(path, f)
if os.path.isdir(p):
crawl(brick_path, p, ignore_dirs)
else:
hash = md5(f).hexdigest()
xattr_key = "{pfx}.{pgfid}.{hash}".format(pfx=PFX,
pgfid=pgfid,
hash=hash)
xattr_value = f
xattr.set(p, xattr_key, xattr_value, nofollow=True)
if __name__ == "__main__":
brick = sys.argv[1]
ignore_dirs = [os.path.join(brick, v) for v in IGNORE_DIRS]
crawl(brick, brick, ignore_dirs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment