fix to sksdump
This commit is contained in:
parent
6dbc713dc9
commit
f652aa7c35
@ -72,10 +72,14 @@ def destPrep():
|
|||||||
PAST = NOW - datetime.timedelta(days = sks['days'])
|
PAST = NOW - datetime.timedelta(days = sks['days'])
|
||||||
for thisdir, dirs, files in os.walk(sks['destdir'], topdown = False):
|
for thisdir, dirs, files in os.walk(sks['destdir'], topdown = False):
|
||||||
for f in files:
|
for f in files:
|
||||||
|
try: # we use a try here because if the link's broken, the script bails out.
|
||||||
fstat = os.stat(os.path.join(thisdir, f))
|
fstat = os.stat(os.path.join(thisdir, f))
|
||||||
mtime = fstat.st_mtime
|
mtime = fstat.st_mtime
|
||||||
if int(mtime) < PAST.timestamp():
|
if int(mtime) < PAST.timestamp():
|
||||||
os.remove(os.path.join(thisdir, f))
|
os.remove(os.path.join(thisdir, f))
|
||||||
|
except FileNotFoundError: # broken symlink
|
||||||
|
try:
|
||||||
|
os.remove(os.path.join(thisdir, f))
|
||||||
# Delete if empty dir
|
# Delete if empty dir
|
||||||
if len(os.listdir(thisdir)) == 0:
|
if len(os.listdir(thisdir)) == 0:
|
||||||
os.rmdir(thisdir)
|
os.rmdir(thisdir)
|
||||||
@ -90,7 +94,7 @@ def destPrep():
|
|||||||
if getpass.getuser() == 'root':
|
if getpass.getuser() == 'root':
|
||||||
uid = getpwnam(sks['user']).pw_uid
|
uid = getpwnam(sks['user']).pw_uid
|
||||||
gid = getgrnam(sks['group']).gr_gid
|
gid = getgrnam(sks['group']).gr_gid
|
||||||
for d in (sks['destdir'], nowdir):
|
for d in (sks['destdir'], nowdir): # we COULD set it as part of the os.makedirs, but iirc it doesn't set it for existing dirs
|
||||||
os.chown(d, uid, gid)
|
os.chown(d, uid, gid)
|
||||||
if os.path.isdir(curdir):
|
if os.path.isdir(curdir):
|
||||||
os.remove(curdir)
|
os.remove(curdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user