rest-ftp-daemon 0.242.5 → 0.243

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99420738a087bcca94f2edc12c0db0e7666b6d84
4
- data.tar.gz: 01d13c3a2165f7526c9c5ffb688bffe0cdfb65de
3
+ metadata.gz: 8289d36947f2e57440398bc166b4937a8d84455d
4
+ data.tar.gz: 9438a30f9e2bb7c6bca9e430fad8755de074c7af
5
5
  SHA512:
6
- metadata.gz: ccfa3b6c24d2e500f841500944e8e429281d68e8440471c84e530ded779a8d6b339041a9b02c64d9ffcdcceb87f228ea9fe9e51ab9381f218080949b282aae4e
7
- data.tar.gz: a17c9f7a94be0f7afb5f29dc84f3c24151e9262070be636bfa200f57a7aca3a47834d28be9b6a548968d6e50ddcbb3360f998f673da7ca2d50c8968168fecd6a
6
+ metadata.gz: 76c1d06af488c24dd36fe4a8ad78ce5670040fc4c5d6be5d69837479de7051a98ad82750fff8054af7a0defdc075d728dd9ab3385a456e3be9fb9798bdbb7e7e
7
+ data.tar.gz: 081de80b07433233ce8d9e0462d6b3d22ce6b98d30b3db494d9385bae995a95e4277460e3823f89f367ade4ed6173db8180e416281fe8effe3df77a7d604767c
data/.rubocop.yml CHANGED
@@ -432,7 +432,7 @@ Style/HashSyntax:
432
432
  UseHashRocketsWithSymbolValues: false
433
433
 
434
434
  Style/IfUnlessModifier:
435
- MaxLineLength: 120
435
+ MaxLineLength: 160
436
436
 
437
437
  Style/IndentationConsistency:
438
438
  # The difference between `rails` and `normal` is that the `rails` style
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-ftp-daemon (0.242.5)
4
+ rest-ftp-daemon (0.243)
5
5
  double-bag-ftps
6
6
  facter
7
7
  get_process_mem
@@ -19,7 +19,7 @@ GEM
19
19
  remote: http://rubygems.org/
20
20
  specs:
21
21
  CFPropertyList (2.2.8)
22
- activesupport (4.2.4)
22
+ activesupport (4.2.5)
23
23
  i18n (~> 0.7)
24
24
  json (~> 1.7, >= 1.7.7)
25
25
  minitest (~> 5.1)
@@ -79,7 +79,7 @@ GEM
79
79
  ice_nine (0.11.1)
80
80
  json (1.8.3)
81
81
  method_source (0.8.2)
82
- minitest (5.8.2)
82
+ minitest (5.8.3)
83
83
  multi_json (1.11.2)
84
84
  multi_xml (0.5.5)
85
85
  net-sftp (2.1.2)
@@ -100,19 +100,19 @@ GEM
100
100
  rack (>= 1.0.0)
101
101
  rainbow (2.0.0)
102
102
  rake (10.4.2)
103
- rspec (3.3.0)
104
- rspec-core (~> 3.3.0)
105
- rspec-expectations (~> 3.3.0)
106
- rspec-mocks (~> 3.3.0)
107
- rspec-core (3.3.2)
108
- rspec-support (~> 3.3.0)
109
- rspec-expectations (3.3.1)
103
+ rspec (3.4.0)
104
+ rspec-core (~> 3.4.0)
105
+ rspec-expectations (~> 3.4.0)
106
+ rspec-mocks (~> 3.4.0)
107
+ rspec-core (3.4.1)
108
+ rspec-support (~> 3.4.0)
109
+ rspec-expectations (3.4.0)
110
110
  diff-lcs (>= 1.2.0, < 2.0)
111
- rspec-support (~> 3.3.0)
112
- rspec-mocks (3.3.2)
111
+ rspec-support (~> 3.4.0)
112
+ rspec-mocks (3.4.0)
113
113
  diff-lcs (>= 1.2.0, < 2.0)
114
- rspec-support (~> 3.3.0)
115
- rspec-support (3.3.0)
114
+ rspec-support (~> 3.4.0)
115
+ rspec-support (3.4.1)
116
116
  rubocop (0.32.1)
117
117
  astrolabe (~> 1.3)
118
118
  parser (>= 2.2.2.5, < 3.0)
data/bin/rest-ftp-daemon CHANGED
@@ -58,7 +58,7 @@ end
58
58
  # Load config, and merge options from ARGV into settings
59
59
  # FIXME: file configuration detection could reside in settings.rb
60
60
  APP_CONF ||= DEFAULT_CONFIG_PATH
61
- APP_ENV ||= "production"
61
+ APP_ENV ||= "production"
62
62
  abort "EXITING: cannot read configuration file: #{APP_CONF}" unless File.exist? APP_CONF
63
63
  begin
64
64
  # Import settings
data/config.ru CHANGED
@@ -29,8 +29,8 @@ unless Settings.namespace == "production"
29
29
  end
30
30
 
31
31
  # Set up encodings
32
- # Encoding.default_internal = "utf-8"
33
- # Encoding.default_external = "utf-8"
32
+ Encoding.default_internal = "utf-8"
33
+ Encoding.default_external = "utf-8"
34
34
 
35
35
  # Launch the main daemon
36
36
  run RestFtpDaemon::API::Root
@@ -18,7 +18,9 @@ module RestFtpDaemon
18
18
 
19
19
  def render name, values={}
20
20
  template = File.read("#{APP_LIBS}/views/#{name}.haml")
21
- haml_engine = Haml::Engine.new(template)
21
+
22
+ haml_engine = Haml::Engine.new(template, encoding: Encoding::UTF_8)
23
+ #:encoding => Encoding::ASCII_8BIT
22
24
  haml_engine.render(binding, values)
23
25
  end
24
26
  end
@@ -15,9 +15,9 @@ module RestFtpDaemon
15
15
  expose :wid, unless: lambda { |object, _options| object.wid.nil? }
16
16
 
17
17
  # expose :error
18
- expose :error_utf8, :as => :error
19
- expose :status_utf8, :as => :status
20
- expose :target_method_utf8, :as => :target_method
18
+ expose :error_utf8, as: :error
19
+ expose :status_utf8, as: :status
20
+ expose :target_method_utf8, as: :target_method
21
21
 
22
22
  expose :queued_at
23
23
  expose :updated_at
@@ -1,7 +1,7 @@
1
1
  # Terrific constants
2
2
  APP_NAME = "rest-ftp-daemon"
3
3
  APP_NICK = "rftpd"
4
- APP_VER = "0.242.5"
4
+ APP_VER = "0.243"
5
5
 
6
6
  # Provide default config file information
7
7
  APP_LIB = File.expand_path File.dirname(__FILE__)
@@ -36,9 +36,15 @@ JOB_UPDATE_INTERVAL = 1
36
36
 
37
37
 
38
38
  # Jobs and workers statuses
39
+ JOB_STATUS_PREPARING = :preparing
40
+ JOB_STATUS_RUNNING = :running
41
+ JOB_STATUS_CHECKING_SRC = :checking_source
42
+ JOB_STATUS_CONNECTING = :remote_connect
43
+ JOB_STATUS_CHDIR = :remote_chdir
39
44
  JOB_STATUS_UPLOADING = :uploading
40
45
  JOB_STATUS_RENAMING = :renaming
41
46
  JOB_STATUS_PREPARED = :prepared
47
+ JOB_STATUS_DISCONNECTING= :remote_disconnect
42
48
  JOB_STATUS_FINISHED = :finished
43
49
  JOB_STATUS_FAILED = :failed
44
50
  JOB_STATUS_QUEUED = :queued
@@ -57,7 +63,7 @@ LOG_PIPE_LEN = 10
57
63
  LOG_COL_WID = 8
58
64
  LOG_COL_JID = JOB_IDENT_LEN + 3 + 2
59
65
  LOG_COL_ID = 6
60
- LOG_TRIM_LINE = 80
66
+ LOG_TRIM_LINE = 200
61
67
  LOG_DUMPS = File.dirname(__FILE__) + "/../../log/"
62
68
  LOG_ROTATION = "daily"
63
69
  LOG_FORMAT_TIME = "%Y-%m-%d %H:%M:%S"
@@ -12,8 +12,8 @@ module RestFtpDaemon
12
12
  return "&Oslash;" if number.nil? || number.to_f.zero?
13
13
 
14
14
  units = ["", "k", "M", "G", "T", "P" ]
15
- index = ( Math.log( number ) / Math.log( 2 ) ).to_i / 10
16
- converted = number.to_f / ( 1024 ** index )
15
+ index = ( Math.log(number) / Math.log(2) ).to_i / 10
16
+ converted = number.to_f / (1024 ** index)
17
17
 
18
18
  truncated = converted.round(decimals)
19
19
 
@@ -61,20 +61,18 @@ module RestFtpDaemon
61
61
  end
62
62
 
63
63
  def self.local_port_used? port
64
- begin
65
- Timeout.timeout(BIND_PORT_TIMEOUT) do
66
- begin
67
- TCPSocket.new(BIND_PORT_LOCALHOST, port).close
68
- true
69
- rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
70
- false
71
- rescue Errno::EADDRNOTAVAIL
72
- "Settings.local_port_used: Errno::EADDRNOTAVAIL"
73
- end
64
+ Timeout.timeout(BIND_PORT_TIMEOUT) do
65
+ begin
66
+ TCPSocket.new(BIND_PORT_LOCALHOST, port).close
67
+ true
68
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
69
+ false
70
+ rescue Errno::EADDRNOTAVAIL
71
+ "Settings.local_port_used: Errno::EADDRNOTAVAIL"
74
72
  end
75
- rescue Timeout::Error
76
- false
77
73
  end
74
+ rescue Timeout::Error
75
+ false
78
76
  end
79
77
 
80
78
  def self.job_method_label method
@@ -21,7 +21,6 @@ module RestFtpDaemon
21
21
  attr_reader :runs
22
22
  attr_reader :target_method
23
23
 
24
-
25
24
  attr_reader :queued_at
26
25
  attr_reader :updated_at
27
26
  attr_reader :started_at
@@ -93,7 +92,6 @@ module RestFtpDaemon
93
92
 
94
93
  # Prepare job
95
94
  begin
96
- set_status :prepare
97
95
  prepare
98
96
 
99
97
  rescue RestFtpDaemon::JobMissingAttribute => exception
@@ -108,12 +106,12 @@ module RestFtpDaemon
108
106
  rescue RestFtpDaemon::JobTargetUnsupported => exception
109
107
  return oops :started, exception, :target_unsupported
110
108
 
111
- rescue URI::InvalidURIError => exception
112
- return oops :started, exception, :target_invalid
113
-
114
109
  rescue RestFtpDaemon::JobAssertionFailed => exception
115
110
  return oops :started, exception, :assertion_failed
116
111
 
112
+ rescue URI::InvalidURIError => exception
113
+ return oops :started, exception, :target_invalid
114
+
117
115
  else
118
116
  # Prepare done !
119
117
  set_status JOB_STATUS_PREPARED
@@ -123,8 +121,8 @@ module RestFtpDaemon
123
121
 
124
122
  # Process job
125
123
  begin
126
- set_status :starting
127
- transfer
124
+ #raise Net::FTPTempError, '451 Téléchargement avorté. Input/output error'.force_encoding("ASCII-8BIT")
125
+ start
128
126
 
129
127
  rescue SocketError => exception
130
128
  return oops :ended, exception, :conn_socket_error
@@ -174,6 +172,9 @@ module RestFtpDaemon
174
172
  rescue Errno::EINVAL => exception
175
173
  return oops :ended, exception, :invalid_argument, true
176
174
 
175
+ rescue Encoding::UndefinedConversionError => exception
176
+ return oops :ended, exception, :encoding_error, true
177
+
177
178
  rescue RestFtpDaemon::JobSourceNotFound => exception
178
179
  return oops :ended, exception, :source_not_found
179
180
 
@@ -284,7 +285,7 @@ module RestFtpDaemon
284
285
 
285
286
  def prepare
286
287
  # Update job status
287
- set_status :prepare
288
+ set_status JOB_STATUS_PREPARING
288
289
  @runs += 1
289
290
 
290
291
  # Init
@@ -307,7 +308,6 @@ module RestFtpDaemon
307
308
  #puts "@target_path: #{@target_path.inspect}"
308
309
 
309
310
  # Prepare remote
310
- set_status :remote_init
311
311
  #FIXME: use a "case" statement on @target_url.class
312
312
 
313
313
  if target_uri.is_a? URI::FTP
@@ -335,33 +335,34 @@ module RestFtpDaemon
335
335
  end
336
336
  end
337
337
 
338
- def transfer
338
+ def run
339
339
  # Update job status
340
+ set_status JOB_STATUS_RUNNING
340
341
  @started_at = Time.now
341
342
 
342
343
  # Method assertions and init
343
- raise RestFtpDaemon::JobAssertionFailed, "transfer/1" unless @source_path
344
- raise RestFtpDaemon::JobAssertionFailed, "transfer/2" unless @target_path
344
+ raise RestFtpDaemon::JobAssertionFailed, "run/1" unless @source_path
345
+ raise RestFtpDaemon::JobAssertionFailed, "run/2" unless @target_path
345
346
  @transfer_sent = 0
346
347
  set_info :source_processed, 0
347
348
 
348
349
  # Guess source files from disk
349
- set_status :checking_source
350
+ set_status JOB_STATUS_CHECKING_SRC
350
351
  sources = find_local @source_path
351
352
  set_info :source_count, sources.count
352
353
  set_info :source_files, sources.collect(&:full)
353
- log_info "Job.transfer sources #{sources.collect(&:name)}"
354
+ log_info "Job.run sources #{sources.collect(&:name)}"
354
355
  raise RestFtpDaemon::JobSourceNotFound if sources.empty?
355
356
 
356
357
  # Guess target file name, and fail if present while we matched multiple sources
357
358
  raise RestFtpDaemon::JobTargetDirectoryError if @target_path.name && sources.count>1
358
359
 
359
360
  # Connect to remote server and login
360
- set_status :remote_connect
361
+ set_status JOB_STATUS_CONNECTING
361
362
  @remote.connect
362
363
 
363
364
  # Prepare target path or build it if asked
364
- set_status :remote_chdir
365
+ set_status JOB_STATUS_CHDIR
365
366
  @remote.chdir_or_create @target_path.dir, @mkdir
366
367
 
367
368
  # Compute total files size
@@ -394,8 +395,6 @@ module RestFtpDaemon
394
395
  finalize
395
396
  end
396
397
 
397
-
398
-
399
398
  private
400
399
 
401
400
  def log_context
@@ -422,7 +421,18 @@ module RestFtpDaemon
422
421
  def set_info attribute, value
423
422
  @mutex.synchronize do
424
423
  @infos || {}
425
- @infos[attribute] = utf8_if_string value
424
+
425
+ # Force strings to UTF8
426
+ if value.is_a? Symbol
427
+ @infos[attribute] = value.to_s.force_encoding(Encoding::UTF_8)
428
+ elsif value.is_a? String
429
+ # @infos[attribute] = utf8(value)
430
+ @infos[attribute] = value.force_encoding(Encoding::UTF_8)
431
+ else
432
+ @infos[attribute] = value
433
+ end
434
+
435
+ # Mark the job as updated
426
436
  touch_job
427
437
  end
428
438
  end
@@ -432,27 +442,15 @@ module RestFtpDaemon
432
442
  end
433
443
 
434
444
  def set_error value
435
- @error = value
445
+ @error = utf8(value.to_s)
436
446
  touch_job
437
447
  end
438
448
 
439
449
  def set_status value
440
- @status = value
450
+ @status = utf8(value.to_s)
441
451
  touch_job
442
452
  end
443
453
 
444
- # def set_status value
445
- # @mutex.synchronize do
446
- # @status = utf8_if_string value
447
- # touch_job
448
- # end
449
- # end
450
-
451
- def utf8_if_string value
452
- return value unless (value.is_a? String) || (value.is_a? Symbol)
453
- return utf8 value
454
- end
455
-
456
454
  def flag_default name, default
457
455
  # build the flag instance var name
458
456
  variable = "@#{name}"
@@ -473,7 +471,7 @@ module RestFtpDaemon
473
471
  @remote = nil
474
472
 
475
473
  # Update job status
476
- set_status :disconnecting
474
+ set_status JOB_STATUS_DISCONNECTING
477
475
  @finished_at = Time.now
478
476
 
479
477
  # Update counters
@@ -483,9 +481,9 @@ module RestFtpDaemon
483
481
 
484
482
  def remote_push source, target
485
483
  # Method assertions
486
- raise RestFtpDaemon::JobAssertionFailed, "ftp_transfer/1" if @remote.nil?
487
- raise RestFtpDaemon::JobAssertionFailed, "ftp_transfer/2" if source.nil?
488
- raise RestFtpDaemon::JobAssertionFailed, "ftp_transfer/3" if target.nil?
484
+ raise RestFtpDaemon::JobAssertionFailed, "remote_push/1" if @remote.nil?
485
+ raise RestFtpDaemon::JobAssertionFailed, "remote_push/2" if source.nil?
486
+ raise RestFtpDaemon::JobAssertionFailed, "remote_push/3" if target.nil?
489
487
 
490
488
  # Use source filename if target path provided none (typically with multiple sources)
491
489
  log_info "Job.remote_push [#{source.name}]: [#{source.full}] > [#{target.full}]"
@@ -510,10 +508,9 @@ module RestFtpDaemon
510
508
  transfer_started_at = Time.now
511
509
  @progress_at = 0
512
510
  @notified_at = transfer_started_at
513
- set_status JOB_STATUS_UPLOADING
514
511
 
515
512
  # Start the transfer, update job status after each block transfer
516
- set_status :uploading
513
+ set_status JOB_STATUS_UPLOADING
517
514
  @remote.push source, target, tempname do |transferred, name|
518
515
  # Update transfer statistics
519
516
  progress transferred, name
@@ -578,7 +575,6 @@ module RestFtpDaemon
578
575
  end
579
576
  end
580
577
 
581
-
582
578
  def client_notify event, payload = {}
583
579
  # Skip if no URL given
584
580
  return unless @notify
@@ -655,7 +651,7 @@ module RestFtpDaemon
655
651
 
656
652
  if Settings.newrelic_enabled?
657
653
  add_transaction_tracer :prepare, category: :task
658
- add_transaction_tracer :transfer, category: :task
654
+ add_transaction_tracer :run, category: :task
659
655
  add_transaction_tracer :client_notify, category: :task
660
656
  add_transaction_tracer :initialize, category: :task
661
657
  end
@@ -25,7 +25,7 @@ class Logger
25
25
  end
26
26
 
27
27
  # Prepend plain message to output
28
- output.unshift prefix1 + message
28
+ output.unshift prefix1 + message.force_encoding(Encoding::UTF_8)
29
29
 
30
30
  # Send all this to logger
31
31
  add context[:level], output
@@ -65,7 +65,7 @@ a.class {
65
65
  }
66
66
 
67
67
  .table-condensed tbody > tr > td {
68
- padding: 3px 3px;
68
+ padding: 2px 3px;
69
69
  }
70
70
 
71
71
  #box-jobs .error {
@@ -38,7 +38,7 @@ module RestFtpDaemon
38
38
  if !job.error
39
39
  #log_info "job succeeded"
40
40
 
41
- elsif !(on_errors.is_a?(Enumerable) && on_errors.include?(job.error.to_s))
41
+ elsif !(on_errors.is_a?(Enumerable) && on_errors.include?(job.error))
42
42
  log_error "not retrying: error not eligible"
43
43
 
44
44
  elsif max_age && (job.age >= max_age)
@@ -93,7 +93,7 @@ module RestFtpDaemon
93
93
  job.oops_you_stop_now ex unless job.nil?
94
94
 
95
95
  rescue StandardError => ex
96
- log_error "JOB UNHANDLED EXCEPTION: #{ex.message}", ex.backtrace
96
+ log_error "JOB UNHANDLED EXCEPTION ex[#{ex.class}] #{ex.message}", ex.backtrace
97
97
  worker_status WORKER_STATUS_CRASHED
98
98
 
99
99
  # Inform the job
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-ftp-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.242.5
4
+ version: '0.243'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler