• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Commit MetaInfo

Revisionf28d000e44207c4dca490e954eda1e08cfc381e3 (tree)
Time2018-08-20 18:52:46
AuthorTatsuki Sugiura <sugi@nemu...>
CommiterTatsuki Sugiura

Log Message

Update to compat API change (no digest infomation when file uploaded).

Change Summary

Incremental Difference

--- a/lib/osdn/cli.rb
+++ b/lib/osdn/cli.rb
@@ -165,6 +165,13 @@ module OSDN
165165 logger.warn "Failed to load variables from #{path}; #{e.message}"
166166 end
167167 end
168+ # Fix key conflicts
169+ if vars['local_file_info']
170+ vars['local_file_info'].each do |fname, finfo|
171+ finfo.has_key?('size') or next
172+ finfo['filesize'] = finfo.delete('size')
173+ end
174+ end
168175 logger.debug "Variables: #{vars.inspect}"
169176 Hashie::Mash.new(vars)
170177 end
--- a/lib/osdn/cli/command/frs_upload.rb
+++ b/lib/osdn/cli/command/frs_upload.rb
@@ -1,5 +1,7 @@
11 module OSDN; module CLI; module Command
22 class FrsUpload < Base
3+ attr_accessor :target_proj, :visibility, :force_digest, :dry_run, :show_progress
4+
35 def help
46 puts "#{$0} frs_upload [opts] [target_dir]"
57 puts "Options:"
@@ -164,67 +166,31 @@ module OSDN; module CLI; module Command
164166 return false
165167 end
166168
167- vars = load_variables(rdir)
168- digests = nil
169- if !@force_digest && vars.local_file_info &&
170- vars.local_file_info[file.basename.to_s]
171- finfo = vars.local_file_info[file.basename.to_s]
172- if finfo[:size] == file.size && finfo.mtime == file.mtime
173- digests = vars.local_file_info[file.basename.to_s].digests
174- end
169+ filecmd = Relfile.new logger
170+ [:target_proj, :visibility, :force_digest, :show_progress].each do |opt|
171+ filecmd.send "#{opt}=", send(opt)
175172 end
173+ filecmd.target_package = target_package(rdir)
174+ filecmd.target_release = target_release(rdir)
175+ filecmd.calc_file_digest(file)
176+
177+ vars = load_variables(rdir)
178+ digests = vars.local_file_info[file.basename.to_s].digests
176179
177- unless digests
178- logger.info "Calculating digest for #{file}..."
179- digests = {
180- sha256: hexdigest(Digest::SHA256, file),
181- sha1: hexdigest(Digest::SHA1, file),
182- md5: hexdigest(Digest::MD5, file),
183- }
184- update_variables rdir, {local_file_info: {file.basename.to_s => {digests: digests, mtime: file.mtime, size: file.size}}}
185- end
186180 if remote_f = rinfo.files.find { |f| f.name == file.basename.to_s }
187- if digests.find { |type, dig| dig != remote_f.send("digest_#{type}") }
181+ if remote_f.size != file.size || digests.find { |type, dig| rd = remote_f.send("digest_#{type}"); rd && rd != '' && dig != rd }
188182 logger.error "#{file} was changed from remote file! Please delete remote file before uploading new one."
189183 end
190184 logger.info "Skip already uploaded file '#{file}'"
191185 return
192186 end
193187
188+ finfo = {}
194189 logger.info "Uploading file #{file} (#{file.size} bytes)"
195190 if @dry_run
196191 finfo = Hashie::Mash.new id: '(dry-run)', url: '(dry-run)'
197192 else
198- logger.level <= Logger::INFO && @show_progress != false || @show_progress and
199- OSDN::CLI._show_progress = true
200- fio = file.open
201- logger.info "Starting upload #{file}..."
202- max_upload_tries = 5
203- upload_tries = 0
204- begin
205- upload_tries += 1
206- finfo = api.create_release_file target_proj, target_package(rdir), target_release(rdir), fio, visibility: @visibility
207- rescue OSDNClient::ApiError => e
208- if max_upload_tries - upload_tries <= 0
209- logger.error "Max upload attempts (#{max_upload_tries}) has been exceeded, give up!"
210- raise e
211- elsif [0, 100, 502].member?(e.code.to_i)
212- fio.rewind
213- logger.error "Upload error (#{e.code} #{e.message}), retrying (#{upload_tries}/#{max_upload_tries})..."
214- sleep 10
215- retry
216- else
217- raise e
218- end
219- ensure
220- OSDN::CLI._show_progress = false
221- fio.close
222- end
223- if digests.find { |type, dig| dig != finfo.send("digest_#{type}") }
224- logger.error "File digests are mismatch! Upload file #{file} may be broken! Please check."
225- else
226- logger.info "Upload complete."
227- end
193+ finfo = filecmd.create_one file
228194 end
229195 $stdout.puts "New file '#{file}' has been uploaded; #{finfo.url}"
230196 end
--- a/lib/osdn/cli/command/relfile.rb
+++ b/lib/osdn/cli/command/relfile.rb
@@ -3,6 +3,8 @@ require 'pathname'
33
44 module OSDN; module CLI; module Command
55 class Relfile < FrsBase
6+ attr_accessor :target_proj, :target_package, :target_release, :visibility, :force_digest, :show_progress
7+
68 def help
79 puts "#{$0} relfile [opts] [list]"
810 puts "#{$0} relfile [opts] create <target-file> [target-files...]"
@@ -93,16 +95,14 @@ module OSDN; module CLI; module Command
9395 end
9496 end
9597
96- def create_one(filename)
98+ def calc_file_digest(filename)
9799 file = Pathname('.') + filename
98- logger.debug "Calculating digest for #{file}..."
99-
100100 vars = load_variables(file.dirname)
101101 digests = nil
102102 if !@force_digest && vars.local_file_info &&
103- vars.local_file_info[file.basename.to_s]
103+ vars.local_file_info[file.basename.to_s]
104104 finfo = vars.local_file_info[file.basename.to_s]
105- if finfo[:size] == file.size && finfo.mtime == file.mtime
105+ if finfo.filesize == file.size && finfo.mtime == file.mtime
106106 digests = vars.local_file_info[file.basename.to_s].digests
107107 end
108108 end
@@ -114,19 +114,24 @@ module OSDN; module CLI; module Command
114114 sha1: hexdigest(Digest::SHA1, file),
115115 md5: hexdigest(Digest::MD5, file),
116116 }
117- update_variables file.dirname, {local_file_info: {file.basename.to_s => {digests: digests, mtime: file.mtime, size: file.size}}}
117+ update_variables file.dirname, {local_file_info: {file.basename.to_s => {digests: digests, mtime: file.mtime, filesize: file.size}}}
118118 end
119+ end
119120
121+ def create_one(filename)
122+ file = Pathname('.') + filename
123+ calc_file_digest file
124+ vars = load_variables(file.dirname)
120125 fio = file.open
121126 logger.level <= Logger::INFO && @show_progress != false || @show_progress and
122127 OSDN::CLI._show_progress = true
123- logger.info "Starting upload #{file}..."
128+ logger.info "Starting upload #{file} (#{file.size} bytes)..."
124129 max_upload_tries = 5
125130 upload_tries = 0
126- f = nil
131+ remote_file = nil
127132 begin
128133 upload_tries += 1
129- f = api.create_release_file target_proj, target_package, target_release, fio, visibility: @visibility
134+ remote_file = api.create_release_file target_proj, target_package, target_release, fio, visibility: @visibility
130135 rescue OSDNClient::ApiError => e
131136 if max_upload_tries - upload_tries <= 0
132137 logger.error "Max upload attempts (#{max_upload_tries}) has been exceeded, give up!"
@@ -144,12 +149,15 @@ module OSDN; module CLI; module Command
144149 OSDN::CLI._show_progress = false
145150 end
146151
147- if digests.find { |type, dig| dig != f.send("digest_#{type}") }
148- logger.error "File digests are mismatch! Upload file #{file} may be broken! Please check."
152+ if vars.local_file_info[file.basename.to_s].digests.find { |type, dig| rd = remote_file.send("digest_#{type}"); rd && rd != '' && rd != dig }
153+ logger.error "File digest mismatch! Uploaded file #{file} may be broken! Please check."
154+ elsif file.size != remote_file.size
155+ logger.error "File size mismatch! Uploaded file #{file} may be broken! Please check."
149156 else
150157 logger.info "Upload complete."
151158 end
152- puts format_file(f)
159+ puts format_file(remote_file)
160+ remote_file
153161 end
154162
155163 def update