#48 revisions without a physical file

This commit is contained in:
Karel Picman 2017-07-21 09:02:29 +02:00
parent 956767799c
commit 95a30d4d0b
8 changed files with 23 additions and 12 deletions

View File

@ -151,7 +151,7 @@ class DmsfFilesController < ApplicationController
if revision.save if revision.save
revision.assign_workflow(params[:dmsf_workflow_id]) revision.assign_workflow(params[:dmsf_workflow_id])
if upload if upload
FileUtils.mv(upload.tempfile_path, revision.disk_file) FileUtils.mv(upload.tempfile_path, revision.disk_file(false))
end end
if @file.locked? && !@file.locks.empty? if @file.locked? && !@file.locks.empty?
begin begin

View File

@ -96,8 +96,8 @@ module DmsfUploadHelper
if new_revision.save if new_revision.save
new_revision.assign_workflow(commited_file[:dmsf_workflow_id]) new_revision.assign_workflow(commited_file[:dmsf_workflow_id])
begin begin
FileUtils.mv commited_file[:tempfile_path], new_revision.disk_file FileUtils.mv commited_file[:tempfile_path], new_revision.disk_file(false)
FileUtils.chmod 'u=wr,g=r', new_revision.disk_file FileUtils.chmod 'u=wr,g=r', new_revision.disk_file(false)
file.set_last_revision new_revision file.set_last_revision new_revision
files.push(file) files.push(file)
if file.container.is_a?(Issue) if file.container.is_a?(Issue)

View File

@ -271,7 +271,7 @@ class DmsfFile < ActiveRecord::Base
new_revision.dmsf_file = file new_revision.dmsf_file = file
new_revision.disk_filename = new_revision.new_storage_filename new_revision.disk_filename = new_revision.new_storage_filename
if File.exist? self.last_revision.disk_file if File.exist? self.last_revision.disk_file
FileUtils.cp self.last_revision.disk_file, new_revision.disk_file FileUtils.cp self.last_revision.disk_file, new_revision.disk_file(false)
end end
new_revision.comment = l(:comment_copied_from, :source => "#{project.identifier}: #{self.dmsf_path_str}") new_revision.comment = l(:comment_copied_from, :source => "#{project.identifier}: #{self.dmsf_path_str}")
new_revision.custom_values = [] new_revision.custom_values = []

View File

@ -140,10 +140,21 @@ class DmsfFileRevision < ActiveRecord::Base
DmsfFile.storage_path.join path DmsfFile.storage_path.join path
end end
def disk_file def disk_file(search_if_not_exists = true)
path = self.storage_base_path path = self.storage_base_path
FileUtils.mkdir_p(path) unless File.exist?(path) FileUtils.mkdir_p(path) unless File.exist?(path)
path.join self.disk_filename filename = path.join(self.disk_filename)
if search_if_not_exists
unless File.exist?(filename)
# Let's search for the physical file in source revisions
revisions = self.dmsf_file.dmsf_file_revisions.where(['id < ?', self.id]).order(:id => :desc)
revisions.each do |rev|
filename = rev.disk_file
break if File.exist?(filename)
end
end
end
filename
end end
def new_storage_filename def new_storage_filename

View File

@ -89,12 +89,12 @@ class Dmsf144 < ActiveRecord::Migration
DmsfFileRevision.visible.each {|rev| DmsfFileRevision.visible.each {|rev|
next if rev.project.nil? next if rev.project.nil?
existing = DmsfFile.storage_path.join rev.disk_filename existing = DmsfFile.storage_path.join rev.disk_filename
new_path = rev.disk_file new_path = rev.disk_file(false)
begin begin
if File.exist?(existing) if File.exist?(existing)
if File.exist?(new_path) if File.exist?(new_path)
rev.disk_filename = rev.new_storage_filename rev.disk_filename = rev.new_storage_filename
new_path = rev.disk_file new_path = rev.disk_file(false)
rev.save! rev.save!
end end
#Ensure the project path exists #Ensure the project path exists

View File

@ -28,7 +28,7 @@ class MigrateDocuments < ActiveRecord::Migration
origin = self.disk_file(dmsf_file_revision) origin = self.disk_file(dmsf_file_revision)
if origin if origin
if File.exist?(origin) if File.exist?(origin)
target = dmsf_file_revision.disk_file target = dmsf_file_revision.disk_file(false)
if target if target
unless File.exist?(target) unless File.exist?(target)
begin begin
@ -64,7 +64,7 @@ class MigrateDocuments < ActiveRecord::Migration
DmsfFileRevision.find_each do |dmsf_file_revision| DmsfFileRevision.find_each do |dmsf_file_revision|
if dmsf_file_revision.dmsf_file if dmsf_file_revision.dmsf_file
if dmsf_file_revision.dmsf_file.project if dmsf_file_revision.dmsf_file.project
origin = dmsf_file_revision.disk_file origin = dmsf_file_revision.disk_file(false)
if origin if origin
if File.exist?(origin) if File.exist?(origin)
target = self.disk_file(dmsf_file_revision) target = self.disk_file(dmsf_file_revision)

View File

@ -652,7 +652,7 @@ module RedmineDmsf
# implementation of service for request, which allows for us to pipe a single file through # implementation of service for request, which allows for us to pipe a single file through
# also best-utilising DAV4Rack's implementation. # also best-utilising DAV4Rack's implementation.
def download def download
raise NotFound unless (file && file.last_revision && file.last_revision.disk_file) raise NotFound unless (file && file.last_revision && file.last_revision.disk_file(false))
raise Forbidden unless (!parent.exist? || !parent.folder || DmsfFolder.permissions?(parent.folder)) raise Forbidden unless (!parent.exist? || !parent.folder || DmsfFolder.permissions?(parent.folder))
# If there is no range (start of ranged download, or direct download) then we log the # If there is no range (start of ranged download, or direct download) then we log the

View File

@ -159,7 +159,7 @@ class DmsfConvertDocuments
unless dry unless dry
FileUtils.cp(attachment.diskfile, revision.disk_file) FileUtils.cp(attachment.diskfile, revision.disk_file)
revision.size = File.size(revision.disk_file) revision.size = File.size(revision.disk_file(false))
end end
if dry if dry