witten
/
luminotes
Archived
1
0
Fork 0

Now purging files from the database/filesystem when notes they're linked from

are deleted from the trash. Also displaying a message when deleting a file
manually via the "delete" button.
This commit is contained in:
Dan Helfman 2008-02-22 21:08:29 +00:00
parent db1bc247ad
commit 36b11805c6
3 changed files with 12 additions and 5 deletions

View File

@ -531,23 +531,26 @@ class Files( object ):
return dict()
def purge_unused( self, note ):
def purge_unused( self, note, purge_all_links = False ):
"""
Delete files that were linked from the given note but no longer are.
@type note: model.Note
@param note: note to search for file links
@type ignore_file_links: bool
@param ignore_file_links: if True, delete all files that are/were linked from this note
"""
# load metadata for all files with the given note's note_id
files = self.__database.select_many( File, File.sql_load_note_files( note.object_id ) )
files_to_delete = dict( [ ( db_file.object_id, db_file ) for db_file in files ] )
# search through the note's contents for current links to files
for match in self.FILE_LINK_PATTERN.finditer( note.contents ):
file_id = match.groups( 0 )[ 0 ]
if purge_all_links is False:
for match in self.FILE_LINK_PATTERN.finditer( note.contents ):
file_id = match.groups( 0 )[ 0 ]
# we've found a link for file_id, so don't delete that file
files_to_delete.pop( file_id, None )
# we've found a link for file_id, so don't delete that file
files_to_delete.pop( file_id, None )
# for each file to delete, delete its metadata from the database and its data from the
# filesystem

View File

@ -599,6 +599,7 @@ class Notebooks( object ):
note.notebook_id = notebook.trash_id
note.startup = True
else:
self.__files.purge_unused( note, purge_all_links = True )
note.notebook_id = None
note.user_id = user_id
@ -702,6 +703,7 @@ class Notebooks( object ):
note.notebook_id = notebook.trash_id
note.startup = True
else:
self.__files.purge_unused( note, purge_all_links = True )
note.notebook_id = None
note.user_id = user_id

View File

@ -2489,6 +2489,8 @@ File_link_pulldown.prototype.delete_button_clicked = function ( event ) {
this.link.href = "/files/new";
this.editor.focus();
this.wiki.display_message( 'The file "' + strip( this.filename_field.value ) + '" has been deleted.' );
}
File_link_pulldown.prototype.update_position = function ( anchor, relative_to ) {