Esempio n. 1
0
def gc_exceptions(keep_paths:List[Path])->Tuple[List[DRef],List[RRef]]:
  """ Scans `keep_paths` list for references to Pylightnix storage. Ignores
  unrelated filesystem objects. """
  keep_drefs:List[DRef]=[]
  keep_rrefs:List[RRef]=[]

  def _check(f:str):
    nonlocal keep_drefs, keep_rrefs
    if islink(a):
      rref=path2rref(a)
      if rref is not None:
        keep_rrefs.append(rref)
      else:
        dref=path2dref(a)
        if dref is not None:
          keep_drefs.append(dref)

  for path in keep_paths:
    if islink(path):
      _check(path)
    elif isdir(path):
      for root, dirs, filenames in walk(path, topdown=True):
        for dirname in sorted(dirs):
          a=Path(abspath(join(root, dirname)))
          _check(a)
    else:
      pass
  return keep_drefs,keep_rrefs
Esempio n. 2
0
def dirsize(o: Path) -> int:
    """ Return size in bytes """
    total_size = 0
    for dirpath, dirnames, filenames in walk(o):
        for f in filenames:
            fp = join(dirpath, f)
            if not islink(fp):
                total_size += getsize(fp)
    return total_size
Esempio n. 3
0
 def _iter() -> Iterable[Tuple[str, bytes]]:
     for root, dirs, filenames in walk(abspath(path), topdown=True):
         for filename in sorted(filenames):
             if len(filename) > 0 and filename[0] != '_':
                 localpath = abspath(join(root, filename))
                 if islink(localpath):
                     yield (f'link:{localpath}',
                            encode(readlink(localpath)))
                 with open(localpath, 'rb') as f:
                     yield (localpath, f.read())
Esempio n. 4
0
def dirrw(o: Path) -> None:
    for root, dirs, files in walk(o):
        for d in dirs:
            mode = stat(join(root, d))[ST_MODE]
            chmod(join(root, d), mode | (S_IWRITE))
        for f in files:
            if isfile(f):
                filerw(Path(join(root, f)))
            if islink(f):
                warning(
                    f"Pylightnix doesn't guarantee the consistency of symlink '{f}'"
                )
    chmod(o, stat(o)[ST_MODE] | (S_IWRITE | S_IWGRP | S_IWOTH))