mirror of
https://github.com/neocities/neocities.git
synced 2025-08-03 16:21:52 +02:00
clean up some of the delete code, fix space_used bug (hopefully)
This commit is contained in:
parent
b98d982e5b
commit
96478b25bb
4 changed files with 56 additions and 32 deletions
|
@ -2,4 +2,48 @@ class SiteFile < Sequel::Model
|
|||
unrestrict_primary_key
|
||||
plugin :update_primary_key
|
||||
many_to_one :site
|
||||
|
||||
def before_destroy
|
||||
if is_directory
|
||||
site.site_files_dataset.where(path: /^#{path}\//, is_directory: true).all.each do |site_file|
|
||||
begin
|
||||
site_file.destroy
|
||||
rescue Sequel::NoExistingObject
|
||||
end
|
||||
end
|
||||
|
||||
site.site_files_dataset.where(path: /^#{path}\//, is_directory: false).all.each do |site_file|
|
||||
site_file.destroy
|
||||
end
|
||||
|
||||
begin
|
||||
FileUtils.remove_dir site.files_path(path)
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
begin
|
||||
FileUtils.rm site.files_path(path)
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
|
||||
ext = File.extname(path).gsub(/^./, '')
|
||||
site.screenshots_delete(path) if ext.match Site::HTML_REGEX
|
||||
site.thumbnails_delete(path) if ext.match Site::IMAGE_REGEX
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def after_destroy
|
||||
super
|
||||
unless is_directory
|
||||
DB['update sites set space_used=space_used-? where id=?', size, site_id].first
|
||||
end
|
||||
|
||||
site.delete_cache site.files_path(path)
|
||||
SiteChangeFile.filter(site_id: site_id, filename: path).delete
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue