mirror of https://gitlab.com/bashrc2/epicyon
Recursive delete
parent
655c03e6a1
commit
9fab084e20
18
inbox.py
18
inbox.py
|
@ -20,6 +20,7 @@ from utils import getDomainFromActor
|
|||
from utils import getNicknameFromActor
|
||||
from utils import domainPermitted
|
||||
from utils import locatePost
|
||||
from utils import deletePost
|
||||
from httpsig import verifyPostHeaders
|
||||
from session import createSession
|
||||
from session import getJson
|
||||
|
@ -489,23 +490,6 @@ def receiveUndoLike(session,handle: str,baseDir: str, \
|
|||
undoLikesCollectionEntry(postFilename,messageJson['object'],messageJson['actor'],debug)
|
||||
return True
|
||||
|
||||
def deletePost(baseDir: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
||||
"""
|
||||
"""
|
||||
repliesFilename=postFilename.replace('.json','.replies')
|
||||
if os.path.isfile(repliesFilename):
|
||||
if debug:
|
||||
print('DEBUG: removing replies to '+postFilename)
|
||||
with open(repliesFilename,'r') as f:
|
||||
for replyId in f:
|
||||
replyFile=locatePost(baseDir,nickname,domain,replyId)
|
||||
if replyFile:
|
||||
if os.path.isfile(replyFile):
|
||||
os.remove(replyFile)
|
||||
# remove the replies file itself
|
||||
os.remove(repliesFilename)
|
||||
os.remove(postFilename)
|
||||
|
||||
def receiveDelete(session,handle: str,baseDir: str, \
|
||||
httpPrefix: str,domain :str,port: int, \
|
||||
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
||||
|
|
7
posts.py
7
posts.py
|
@ -33,6 +33,7 @@ from utils import createPersonDir
|
|||
from utils import urlPermitted
|
||||
from utils import getNicknameFromActor
|
||||
from utils import getDomainFromActor
|
||||
from utils import deletePost
|
||||
from capabilities import getOcapFilename
|
||||
from capabilities import capabilitiesUpdate
|
||||
from media import attachImage
|
||||
|
@ -999,16 +1000,14 @@ def archivePostsForPerson(nickname: str,domain: str,baseDir: str, \
|
|||
for postFilename in postsInBox:
|
||||
filePath = os.path.join(boxDir, postFilename)
|
||||
if os.path.isfile(filePath):
|
||||
repliesPath=filePath.replace('.json','.replies')
|
||||
if archiveDir:
|
||||
repliesPath=filePath.replace('.json','.replies')
|
||||
archivePath = os.path.join(archiveDir, postFilename)
|
||||
os.rename(filePath,archivePath)
|
||||
if os.path.isfile(repliesPath):
|
||||
os.rename(repliesPath,archivePath)
|
||||
else:
|
||||
os.remove(filePath)
|
||||
if os.path.isfile(repliesPath):
|
||||
os.remove(repliesPath)
|
||||
deletePost(baseDir,nickname,domain,filePath,False)
|
||||
noOfPosts -= 1
|
||||
if noOfPosts <= maxPostsInBox:
|
||||
break
|
||||
|
|
17
utils.py
17
utils.py
|
@ -141,3 +141,20 @@ def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str,replies=False
|
|||
if not os.path.isfile(postFilename):
|
||||
postFilename=None
|
||||
return postFilename
|
||||
|
||||
def deletePost(baseDir: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
||||
"""Recursively deletes a post and its replies and attachments
|
||||
"""
|
||||
repliesFilename=postFilename.replace('.json','.replies')
|
||||
if os.path.isfile(repliesFilename):
|
||||
if debug:
|
||||
print('DEBUG: removing replies to '+postFilename)
|
||||
with open(repliesFilename,'r') as f:
|
||||
for replyId in f:
|
||||
replyFile=locatePost(baseDir,nickname,domain,replyId)
|
||||
if replyFile:
|
||||
if os.path.isfile(replyFile):
|
||||
deletePost(baseDir,nickname,domain,replyFile,debug)
|
||||
# remove the replies file itself
|
||||
os.remove(repliesFilename)
|
||||
os.remove(postFilename)
|
||||
|
|
Loading…
Reference in New Issue