diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index fd4ef4fc..0233f446 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -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') diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 910efc1a..4af91c1e 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.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)) diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index fa64f3db..ff64161e 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -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}" diff --git a/app/models/dmsf_upload.rb b/app/models/dmsf_upload.rb index 48857c1b..758fd86e 100644 --- a/app/models/dmsf_upload.rb +++ b/app/models/dmsf_upload.rb @@ -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) diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index 195eb9eb..970748c9 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -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 %> <%= l(:label_default) %>: dmsf
<% unless File.exist?(DmsfFile.storage_path) %> <% begin %> - <% Dir.mkdir(DmsfFile.storage_path) %> + <% FileUtils.mkdir_p DmsfFile.storage_path %> <% rescue %> -<%= l(:error_file_storage_directory_does_not_exist) %>
+<%= l(:error_file_storage_directory_does_not_exist) %>
<% end %> <% end %> <% testfilename = DmsfFile.storage_path.join('test.test') %> @@ -88,6 +88,37 @@ <% end %> <% end %> ++ <%= 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 %> + + <%= l(:label_default) %>: <%= Dir.tmpdir %> + +
+<% unless File.exist?(tmpdir) %> + <% begin %> + <% FileUtils.mkdir_p tmpdir %> + <% rescue %> +<%= l(:error_file_tmpdir_does_not_exist) %>
+ <% end %> +<% end %> +<% path = Pathname.new(tmpdir) %> +<% testfilename = path.join('test.test') %> +<% if File.exist?(tmpdir) %> + <% begin %> + <% File.open(testfilename, 'wb') do |file| %> + <% end %> + <% rescue %> +<%= l(:error_tmpfile_can_not_be_created) %>
+ <% ensure %> + <% File.delete(testfilename) if File.exist?(testfilename) %> + <% end %> +<% end %> +<%= content_tag(:label, l(:label_physical_file_delete)) %> <%= check_box_tag('settings[dmsf_really_delete_files]', true, @settings['dmsf_really_delete_files']) %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index e2db6195..7efb3c9e 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -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 diff --git a/config/locales/de.yml b/config/locales/de.yml index 7d3e10fb..4817514e 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index ba013a40..0f3b8d1b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 79913d15..6902e514 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 29564e74..a733a5eb 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 9272e6e3..638b9cbb 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -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 diff --git a/config/locales/it.yml b/config/locales/it.yml index d0a31f70..e85a0db4 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -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 diff --git a/config/locales/ja.yml b/config/locales/ja.yml index a4ca17ae..b1aab635 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -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 diff --git a/config/locales/pl.yml b/config/locales/pl.yml index bea61604..2a6a289d 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -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 diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index fd34e75b..b7456fa9 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -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 diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 96088e75..f566c5af 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -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 diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 88422ca9..b16fcc49 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -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 diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index fbcce82f..3a961980 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -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 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7519c5dc..30599ae1 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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 diff --git a/init.rb b/init.rb index cac92460..a5701848 100644 --- a/init.rb +++ b/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) diff --git a/test/integration/rest_api/dmsf_file_api_test.rb b/test/integration/rest_api/dmsf_file_api_test.rb index d53f2819..45535e91 100644 --- a/test/integration/rest_api/dmsf_file_api_test.rb +++ b/test/integration/rest_api/dmsf_file_api_test.rb @@ -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') diff --git a/test/integration/webdav/dmsf_webdav_move_test.rb b/test/integration/webdav/dmsf_webdav_move_test.rb index 834f60fb..043237ac 100644 --- a/test/integration/webdav/dmsf_webdav_move_test.rb +++ b/test/integration/webdav/dmsf_webdav_move_test.rb @@ -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 diff --git a/test/integration/webdav/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb index 7f528c2c..661b6697 100644 --- a/test/integration/webdav/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -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