forked from indymedia/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 getNicknameFromActor
|
||||||
from utils import domainPermitted
|
from utils import domainPermitted
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
|
from utils import deletePost
|
||||||
from httpsig import verifyPostHeaders
|
from httpsig import verifyPostHeaders
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from session import getJson
|
from session import getJson
|
||||||
|
@ -489,23 +490,6 @@ def receiveUndoLike(session,handle: str,baseDir: str, \
|
||||||
undoLikesCollectionEntry(postFilename,messageJson['object'],messageJson['actor'],debug)
|
undoLikesCollectionEntry(postFilename,messageJson['object'],messageJson['actor'],debug)
|
||||||
return True
|
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, \
|
def receiveDelete(session,handle: str,baseDir: str, \
|
||||||
httpPrefix: str,domain :str,port: int, \
|
httpPrefix: str,domain :str,port: int, \
|
||||||
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
||||||
|
|
7
posts.py
7
posts.py
|
@ -33,6 +33,7 @@ from utils import createPersonDir
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
|
from utils import deletePost
|
||||||
from capabilities import getOcapFilename
|
from capabilities import getOcapFilename
|
||||||
from capabilities import capabilitiesUpdate
|
from capabilities import capabilitiesUpdate
|
||||||
from media import attachImage
|
from media import attachImage
|
||||||
|
@ -999,16 +1000,14 @@ def archivePostsForPerson(nickname: str,domain: str,baseDir: str, \
|
||||||
for postFilename in postsInBox:
|
for postFilename in postsInBox:
|
||||||
filePath = os.path.join(boxDir, postFilename)
|
filePath = os.path.join(boxDir, postFilename)
|
||||||
if os.path.isfile(filePath):
|
if os.path.isfile(filePath):
|
||||||
repliesPath=filePath.replace('.json','.replies')
|
|
||||||
if archiveDir:
|
if archiveDir:
|
||||||
|
repliesPath=filePath.replace('.json','.replies')
|
||||||
archivePath = os.path.join(archiveDir, postFilename)
|
archivePath = os.path.join(archiveDir, postFilename)
|
||||||
os.rename(filePath,archivePath)
|
os.rename(filePath,archivePath)
|
||||||
if os.path.isfile(repliesPath):
|
if os.path.isfile(repliesPath):
|
||||||
os.rename(repliesPath,archivePath)
|
os.rename(repliesPath,archivePath)
|
||||||
else:
|
else:
|
||||||
os.remove(filePath)
|
deletePost(baseDir,nickname,domain,filePath,False)
|
||||||
if os.path.isfile(repliesPath):
|
|
||||||
os.remove(repliesPath)
|
|
||||||
noOfPosts -= 1
|
noOfPosts -= 1
|
||||||
if noOfPosts <= maxPostsInBox:
|
if noOfPosts <= maxPostsInBox:
|
||||||
break
|
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):
|
if not os.path.isfile(postFilename):
|
||||||
postFilename=None
|
postFilename=None
|
||||||
return postFilename
|
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