# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- - 'app/models/attachment.rb'
- 'app/models/setting.rb'
- 'db/schema.rb'
- 'lib/redmine/wiki_formatting/textile/redcloth3.rb'
def reuse_existing_file_if_possible
original_diskfile = nil
-
reused = with_lock do
if existing = Attachment
.where(digest: self.digest, filesize: self.filesize)
self.id, self.disk_filename)
.first
existing.with_lock do
-
original_diskfile = self.diskfile
existing_diskfile = existing.diskfile
-
if File.readable?(original_diskfile) &&
File.readable?(existing_diskfile) &&
FileUtils.identical?(original_diskfile, existing_diskfile)
-
self.update_columns disk_directory: existing.disk_directory,
disk_filename: existing.disk_filename
end
# anymore, thats why this is caught and ignored as well.
end
-
# Physically deletes the file from the file system
def delete_from_disk!
if disk_filename.present? && File.exist?(diskfile)