151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/deb/s3/cli.rb', line 151
def upload(*files)
if files.nil? || files.empty?
error("You must specify at least one file to upload")
end
if missing_file = files.find { |pattern| Dir.glob(pattern).empty? }
error("File '#{missing_file}' doesn't exist")
end
configure_s3_client
begin
if options[:lock]
log("Checking for existing lock file")
log("Locking repository for updates")
Deb::S3::Lock.lock(options[:codename], component, options[:arch], options[:cache_control])
@lock_acquired = true
end
log("Retrieving existing manifests")
release = Deb::S3::Release.retrieve(options[:codename], options[:origin], options[:suite], options[:cache_control])
manifests = {}
release.architectures.each do |arch|
manifests[arch] = Deb::S3::Manifest.retrieve(options[:codename], component, arch, options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
end
packages_arch_all = []
files.collect { |f| Dir.glob(f) }.flatten.each do |file|
log("Examining package file #{File.basename(file)}")
pkg = Deb::S3::Package.parse_file(file)
arch = options[:arch] || pkg.architecture
if options.key?("arch") && options[:arch] != pkg.architecture
warn("You specified architecture #{options[:arch]} but package #{pkg.name} has architecture type of #{pkg.architecture}")
end
error("No architcture given and unable to determine one for #{file}. " +
"Please specify one with --arch [i386|amd64|armhf].") unless arch
if arch == "all" && manifests.count == 0
manifests['amd64'] = Deb::S3::Manifest.retrieve(options[:codename], component,'amd64', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
manifests['i386'] = Deb::S3::Manifest.retrieve(options[:codename], component,'i386', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
manifests['armhf'] = Deb::S3::Manifest.retrieve(options[:codename], component,'armhf', options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
end
manifests[arch] ||= Deb::S3::Manifest.retrieve(options[:codename], component, arch, options[:cache_control], options[:fail_if_exists], options[:skip_package_upload])
begin
manifests[arch].add(pkg, options[:preserve_versions])
rescue Deb::S3::Utils::AlreadyExistsError => e
error("Preparing manifest failed because: #{e}")
end
if arch == 'all'
packages_arch_all << pkg
end
end
manifests.each do |arch, manifest|
next if arch == 'all'
packages_arch_all.each do |pkg|
begin
manifest.add(pkg, options[:preserve_versions], false)
rescue Deb::S3::Utils::AlreadyExistsError => e
error("Preparing manifest failed because: #{e}")
end
end
end
log("Uploading packages and new manifests to S3")
manifests.each_value do |manifest|
begin
manifest.write_to_s3 { |f| sublog("Transferring #{f}") }
rescue Deb::S3::Utils::AlreadyExistsError => e
error("Uploading manifest failed because: #{e}")
end
release.update_manifest(manifest)
end
release.write_to_s3 { |f| sublog("Transferring #{f}") }
log("Update complete.")
ensure
if options[:lock] && @lock_acquired
Deb::S3::Lock.unlock(options[:codename], component, options[:arch], options[:cache_control])
log("Lock released.")
end
end
end
|