Skip to content
This repository was archived by the owner on Feb 19, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,21 @@ def __str__(self):
return "{}: {}".format(created, self.correspondent or self.title)
return str(created)

def find_renamed_document(self, subdirectory=""):
def find_renamed_document(self):
suffix = "%07i.%s" % (self.pk, self.file_type)

# Append .gpg for encrypted files
if self.storage_type == self.STORAGE_TYPE_GPG:
suffix += ".gpg"

# Go up in the directory hierarchy and try to delete all directories
root = os.path.normpath(Document.filename_to_path(subdirectory))
basePath = os.path.normpath(Document.filename_to_path(""))

for filename in os.listdir(root):
if filename.endswith(suffix):
return os.path.join(subdirectory, filename)

fullname = os.path.join(subdirectory, filename)
if os.path.isdir(Document.filename_to_path(fullname)):
return self.find_renamed_document(fullname)
for root, dirnames, filenames in os.walk(basePath):
for filename in filenames:
if filename.endswith(suffix):
fullPath = os.path.join(root, filename)
return os.path.relpath(fullPath, basePath)

return None

Expand Down