Project

General

Profile

Feature #37530 » 37530-v2.patch

Go MAEDA, 2024-05-22 09:42

View differences:

app/views/settings/_display.html.erb
28 28

  
29 29
<p><%= setting_text_field :thumbnails_size, :size => 6 %></p>
30 30

  
31
<p><%= setting_text_field :thumbnails_timeout, :size => 6 %></p>
32

  
31 33
<p><%= setting_select :new_item_menu_tab, [[l(:label_none), '0'], [l(:label_new_project_issue_tab_enabled), '1'], [l(:label_new_object_tab_enabled), '2']] %></p>
32 34
</div>
33 35

  
config/locales/en.yml
494 494
  setting_session_timeout: Session inactivity timeout
495 495
  setting_thumbnails_enabled: Display attachment thumbnails
496 496
  setting_thumbnails_size: Thumbnails size (in pixels)
497
  setting_thumbnails_timeout: Thumbnails creation timeout (in seconds)
497 498
  setting_non_working_week_days: Non-working days
498 499
  setting_jsonp_enabled: Enable JSONP support
499 500
  setting_default_projects_tracker_ids: Default trackers for new projects
config/settings.yml
325 325
thumbnails_size:
326 326
  format: int
327 327
  default: 100
328
thumbnails_timeout:
329
  format: int
330
  default: 10
328 331
non_working_week_days:
329 332
  serialized: true
330 333
  default:
lib/redmine/thumbnail.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
require 'fileutils'
21
require 'timeout'
21 22

  
22 23
module Redmine
23 24
  module Thumbnail
......
51 52
        else
52 53
          cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote target}"
53 54
        end
54
        unless system(cmd)
55
          logger.error("Creating thumbnail failed (#{$?}):\nCommand: #{cmd}")
55

  
56
        pid = nil
57
        begin
58
          Timeout.timeout(Setting.thumbnails_timeout.to_i) do
59
            pid = Process.spawn(cmd)
60
            _, status = Process.wait2(pid)
61
            unless status.success?
62
              logger.error("Creating thumbnail failed (#{status.exitstatus}):\nCommand: #{cmd}")
63
              return nil
64
            end
65
          end
66
        rescue Timeout::Error
67
          begin
68
            Process.kill('TERM', pid)
69
            Timeout.timeout(1) { Process.wait(pid) }
70
          rescue Timeout::Error
71
            Process.kill('KILL', pid)
72
          end
73
          logger.error("Creating thumbnail timed out:\nCommand: #{cmd}")
56 74
          return nil
57 75
        end
58 76
      end
test/unit/attachment_test.rb
626 626
    ensure
627 627
      set_tmp_attachments_directory
628 628
    end
629

  
630
    def test_thumbnail_should_timeout
631
      dummy_pid = 37530
632
      Process.stubs(:spawn).returns(dummy_pid)
633
      Process.stubs(:wait2).raises(Timeout::Error)
634
      Process.stubs(:kill).returns(1)
635
      Process.stubs(:wait).returns(dummy_pid)
636
      Rails.logger.expects(:error).with(regexp_matches(/Creating thumbnail timed out/))
637

  
638
      set_fixtures_attachments_directory
639
      Attachment.clear_thumbnails
640

  
641
      attachment = Attachment.find(16)
642
      thumbnail = attachment.thumbnail
643

  
644
      assert_nil thumbnail
645
    ensure
646
      set_tmp_attachments_directory
647
    end
629 648
  else
630 649
    puts '(ImageMagick convert not available)'
631 650
  end
(3-3/5)