Setting tmp folder path via ENV #736
This commit is contained in:
parent
1a66110202
commit
860d39f9bd
@ -342,7 +342,7 @@ class DmsfController < ApplicationController
|
||||
zip = DmsfZip.new
|
||||
zip_entries(zip, selected_folders, selected_files)
|
||||
|
||||
zipped_content = "#{DmsfHelper.temp_dir}/#{DmsfHelper.temp_filename('dmsf_email_sent_documents.zip')}";
|
||||
zipped_content = DmsfHelper.temp_dir.join(DmsfHelper.temp_filename('dmsf_email_sent_documents.zip'))
|
||||
|
||||
File.open(zipped_content, 'wb') do |f|
|
||||
zip_file = File.open(zip.finish, 'rb')
|
||||
|
||||
@ -67,7 +67,7 @@ class DmsfUploadController < ApplicationController
|
||||
return
|
||||
end
|
||||
@disk_filename = DmsfHelper.temp_filename(@tempfile.original_filename)
|
||||
@tempfile_path = "#{DmsfHelper.temp_dir}/#{@disk_filename}"
|
||||
@tempfile_path = DmsfHelper.temp_dir.join(@disk_filename).to_s
|
||||
File.open(@tempfile_path, 'wb') do |f|
|
||||
if params[:file].respond_to?(:read)
|
||||
while (buffer = @tempfile.read(8192))
|
||||
|
||||
@ -27,13 +27,18 @@ module DmsfHelper
|
||||
include Redmine::I18n
|
||||
|
||||
def self.temp_dir
|
||||
Dir.tmpdir
|
||||
if Setting.plugin_redmine_dmsf['dmsf_tmpdir'].present?
|
||||
tmpdir = Pathname.new(Setting.plugin_redmine_dmsf['dmsf_tmpdir'])
|
||||
else
|
||||
tmpdir = Pathname.new(Dir.tmpdir)
|
||||
end
|
||||
tmpdir
|
||||
end
|
||||
|
||||
def self.temp_filename(filename)
|
||||
filename = sanitize_filename(filename)
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
||||
while File.exist?(File.join(temp_dir, "#{timestamp}_#{filename}"))
|
||||
while self.temp_dir.join("#{timestamp}_#{filename}").exist?
|
||||
timestamp.succ!
|
||||
end
|
||||
"#{timestamp}_#{filename}"
|
||||
|
||||
@ -36,7 +36,7 @@ class DmsfUpload
|
||||
attr_accessor :tempfile_path
|
||||
|
||||
def disk_file
|
||||
"#{DmsfHelper.temp_dir}/#{self.disk_filename}"
|
||||
DmsfHelper.temp_dir.join(self.disk_filename).to_s
|
||||
end
|
||||
|
||||
def self.create_from_uploaded_attachment(project, folder, uploaded_file)
|
||||
|
||||
@ -64,16 +64,16 @@
|
||||
storage_dir = @settings['dmsf_storage_directory'].strip if @settings['dmsf_storage_directory'].present?
|
||||
storage_dir = 'dmsf' if storage_dir.blank?
|
||||
%>
|
||||
<%= text_field_tag 'settings[dmsf_storage_directory]', storage_dir, :size => 50 %>
|
||||
<%= text_field_tag 'settings[dmsf_storage_directory]', storage_dir, :size => 256 %>
|
||||
<em class="info">
|
||||
<%= l(:label_default) %>: dmsf
|
||||
</em>
|
||||
</p>
|
||||
<% unless File.exist?(DmsfFile.storage_path) %>
|
||||
<% begin %>
|
||||
<% Dir.mkdir(DmsfFile.storage_path) %>
|
||||
<% FileUtils.mkdir_p DmsfFile.storage_path %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_file_storage_directory_does_not_exist) %></p>
|
||||
<p class="warning"><%= l(:error_file_storage_directory_does_not_exist) %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% testfilename = DmsfFile.storage_path.join('test.test') %>
|
||||
@ -88,6 +88,37 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= content_tag(:label, l(:label_tmpdir)) %>
|
||||
<%
|
||||
tmpdir = @settings['dmsf_tmpdir'].strip if @settings['dmsf_tmpdir'].present?
|
||||
tmpdir = Dir.tmpdir if tmpdir.blank?
|
||||
%>
|
||||
<%= text_field_tag 'settings[dmsf_tmpdir]', tmpdir, :size => 256 %>
|
||||
<em class="info">
|
||||
<%= l(:label_default) %>: <%= Dir.tmpdir %>
|
||||
</em>
|
||||
</p>
|
||||
<% unless File.exist?(tmpdir) %>
|
||||
<% begin %>
|
||||
<% FileUtils.mkdir_p tmpdir %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_file_tmpdir_does_not_exist) %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% path = Pathname.new(tmpdir) %>
|
||||
<% testfilename = path.join('test.test') %>
|
||||
<% if File.exist?(tmpdir) %>
|
||||
<% begin %>
|
||||
<% File.open(testfilename, 'wb') do |file| %>
|
||||
<% end %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_tmpfile_can_not_be_created) %></p>
|
||||
<% ensure %>
|
||||
<% File.delete(testfilename) if File.exist?(testfilename) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= content_tag(:label, l(:label_physical_file_delete)) %>
|
||||
<%= check_box_tag('settings[dmsf_really_delete_files]', true, @settings['dmsf_really_delete_files']) %>
|
||||
|
||||
@ -362,6 +362,10 @@ cs:
|
||||
label_caching_enabled: Povolit použití vyrovnávací paměti
|
||||
note_webdav_cahing_enabled: Odpovědi na požadavek PROPFIND jsou ukládány do vyrovnávací paměti za účelem zrychlení WebDAV komunikace.
|
||||
|
||||
label_tmpdir: Adresář pro dočasné soubory
|
||||
error_file_tmpdir_does_not_exist: "Adresář pro dočasné soubory neexistuje a nemůže být vytvořen"
|
||||
error_tmpfile_can_not_be_created: "Nelze vytvořit soubor v adresáři pro dočasné soubory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -359,6 +359,10 @@ de:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -170,7 +170,7 @@ en:
|
||||
label_number_of_folders: Folders
|
||||
label_number_of_documents: Documents
|
||||
error_file_storage_directory_does_not_exist: "File storage directory doesn't exist and can't be created"
|
||||
error_file_can_not_be_created: "File can't be created in storage directory"
|
||||
error_file_can_not_be_created: "Files can't be created in storage directory"
|
||||
error_wrong_zip_encoding: Wrong Zip encoding
|
||||
warning_xapian_not_available: Xapian not available
|
||||
menu_dmsf: DMS # Project tab title
|
||||
@ -362,6 +362,10 @@ en:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ es:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ fr:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ hu:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ it: # Italian strings thx 2 Matteo Arceci!
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ ja:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ pl:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ pt-BR:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ ru:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ sl:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ zh-TW:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
@ -362,6 +362,10 @@ zh:
|
||||
label_caching_enabled: Caching enabled
|
||||
note_webdav_cahing_enabled: PROPFIND responses are cached in order to speed up WebDAV communication
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
easy_pages:
|
||||
modules:
|
||||
dmsf_locked_documents: My locked documents
|
||||
|
||||
3
init.rb
3
init.rb
@ -55,7 +55,8 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
'dmsf_keep_documents_locked' => false,
|
||||
'dmsf_act_as_attachable' => false,
|
||||
'dmsf_show_system_folders' => false,
|
||||
'dmsf_webdav_caching_enabled' => false
|
||||
'dmsf_webdav_caching_enabled' => false,
|
||||
'dmsf_tmpdir' => Dir.tmpdir
|
||||
}
|
||||
|
||||
# Uncomment to remove the original Documents from searching (replaced with DMSF)
|
||||
|
||||
@ -77,7 +77,7 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
||||
|
||||
def test_upload_document
|
||||
timestamp = DateTime.now.strftime('%y%m%d%H%M')
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = DmsfHelper.temp_dir.join("dmsf_test-#{timestamp}").to_s
|
||||
FileUtils.mkdir_p(Setting.plugin_redmine_dmsf['dmsf_storage_directory'])
|
||||
@role.add_permission! :file_manipulation
|
||||
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||
|
||||
@ -30,8 +30,8 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest
|
||||
def setup
|
||||
DmsfLock.delete_all # Delete all locks that are in our test DB - probably not safe but ho hum
|
||||
timestamp = DateTime.now.strftime('%y%m%d%H%M')
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Dir.mkdir(DmsfFile.storage_path) unless File.directory?(DmsfFile.storage_path)
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = DmsfHelper.temp_dir.join("dmsf_test-#{timestamp}").to_s
|
||||
FileUtils.mkdir_p(DmsfFile.storage_path) unless DmsfFile.storage_path.exist?
|
||||
# Copy the physical files to the temporary storage
|
||||
files = File.expand_path('../../../fixtures/files', __FILE__) + '/.'
|
||||
FileUtils.cp_r files, DmsfFile.storage_path
|
||||
|
||||
@ -30,8 +30,8 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
||||
def setup
|
||||
DmsfLock.delete_all # Delete all locks that are in our test DB - probably not safe but ho hum
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M")
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Dir.mkdir(DmsfFile.storage_path) unless File.directory?(DmsfFile.storage_path)
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = DmsfHelper.temp_dir.join("dmsf_test-#{timestamp}").to_s
|
||||
FileUtils.mkdir_p(DmsfFile.storage_path) unless DmsfFile.storage_path.exist?
|
||||
@admin = credentials 'admin'
|
||||
@jsmith = credentials 'jsmith'
|
||||
@project1 = Project.find_by_id 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user