def fixxids(self, xid, pace=cfg.PACE[0]): # walk the root, and set all non-iunlink files to xid xid. this # means that when a non iunlink file is deleted, the proper amount # of space is freed. xid = int(xid) print 'Fixing xids in %s for xid %d... (this may take a while)' % ( self.vpsroot, xid) p = 0 t, x = 0, 0 for root, dirs, files in os.walk(self.vpsroot): for file in files + dirs: path = os.path.join(root, file) if pace and p >= pace: sys.stdout.write('.') sys.stdout.flush() time.sleep(cfg.PACE[1]) p = 0 else: p += 1 t += 1 # total file count if os.path.isdir(path) or path.endswith('dev/null') or \ path.endswith('etc/protocols') or path.endswith('etc/resolv.conf'): # do not set xid on directories, as this breaks the ohd # thing which would get permission denied trying to run # stuff from another context. since space (not security) is # the prime motivator for this, and dirs are tiny, this is ok # XXX and of course the dev/null and etc/protocols is a total # dirty hack to make traceroute work # XXX or is it? vsutil.set_file_xid(path, 0) elif (not vsutil.is_file_immutable_unlink(path) and not os.path.islink(path) and os.stat(path).st_nlink == 1): vsutil.set_file_xid(path, xid) x += 1 # setxid file count elif not os.path.islink(path): # default to 0 vsutil.set_file_xid(path, 0) print 'Done.\n%d xids of a total of %d has been set to %d' % (x, t, xid)
def fixxids(self, xid, pace=cfg.PACE[0]): # walk the root, and set all non-iunlink files to xid xid. this # means that when a non iunlink file is deleted, the proper amount # of space is freed. xid = int(xid) print 'Fixing xids in %s for xid %d... (this may take a while)' % (self.vpsroot, xid) p = 0 t, x = 0, 0 for root, dirs, files in os.walk(self.vpsroot): for file in files + dirs: path = os.path.join(root, file) if pace and p >= pace: sys.stdout.write('.'); sys.stdout.flush() time.sleep(cfg.PACE[1]) p = 0 else: p += 1 t += 1 # total file count if os.path.isdir(path) or path.endswith('dev/null') or \ path.endswith('etc/protocols') or path.endswith('etc/resolv.conf'): # do not set xid on directories, as this breaks the ohd # thing which would get permission denied trying to run # stuff from another context. since space (not security) is # the prime motivator for this, and dirs are tiny, this is ok # XXX and of course the dev/null and etc/protocols is a total # dirty hack to make traceroute work # XXX or is it? vsutil.set_file_xid(path, 0) elif (not vsutil.is_file_immutable_unlink(path) and not os.path.islink(path) and os.stat(path).st_nlink == 1): vsutil.set_file_xid(path, xid) x += 1 # setxid file count elif not os.path.islink(path): # default to 0 vsutil.set_file_xid(path, 0) print 'Done.\n%d xids of a total of %d has been set to %d' % (x, t, xid)
def copy(self, src, dst, link=1, touch=0): """Copy a file, a directory or a link. When link is 1 (default), regular files will be hardlinked, as opposed to being copied. When touch is 1, only the file, but not the contents are copied (useful for logfiles). """ if os.path.islink(src): # if it is a symlink, always copy it (no sense in trying # to hardlink a symlink) os.symlink(os.readlink(src), dst) self.copyown(src, dst) self.counter['syms'] += 1 elif os.path.isdir(src): # directories are also copied always os.mkdir(dst) self.copyown(src, dst) shutil.copystat(src, dst) self.counter['drs'] += 1 elif os.path.isfile(src): # this a file, not a dir or symlink if touch: # means create a new file and copy perms open(dst, 'w') self.copyown(src, dst) shutil.copystat(src, dst) self.counter['touchs'] += 1 elif link: # means we should hardlink if vsutil.is_file_immutable_unlink(src): os.link(src, dst) self.counter['lins'] += 1 else: # since it is not iunlink, copy it anyway print 'Warning: not hardlinking %s because it is not iunlink' % src shutil.copy(src, dst) self.copyown(src, dst) shutil.copystat(src, dst) self.counter['bytes'] += os.path.getsize(dst) self.counter['copys'] += 1 else: # else copy it shutil.copy(src, dst) self.copyown(src, dst) shutil.copystat(src, dst) self.counter['bytes'] += os.path.getsize(dst) self.counter['copys'] += 1 else: # this is a special device? s = os.stat(src) if stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode) \ or stat.S_ISFIFO(s.st_mode): os.mknod(dst, s.st_mode, os.makedev(os.major(s.st_rdev), os.minor(s.st_rdev))) self.copyown(src, dst) shutil.copystat(src, dst) self.counter['devs'] += 1