fastlane-plugin-dropbox_upload 0.2.0 → 0.2.1

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: 299fb984bf885cc53d88931f3c8ec109d68e7312
4
- data.tar.gz: a00b781e9669a225ea3d5cc8f7d1b03c4a2553f0
3
+ metadata.gz: d3125d437d27ef16ee2c54448771e36b4020ba6f
4
+ data.tar.gz: a0c44590d99b07192439737e8b4b24347b7f8c40
5
5
  SHA512:
6
- metadata.gz: 74e5c8cd5ad41a48f5e579ed95dcc1d593fb97864d1395537a34d2bf3c40ff4346fd4203fd77e3e0b97d8540dc145dc05ff75f30d896ad1f35ef76e29d104f83
7
- data.tar.gz: 3fb2ad0db6d43e39bfbd67e29a224ddddf7f48c19ad3dc097db1f80e80f64a12396c9e347422bf4e9a3e3a92ae55f4ebff3c5be82f22dac6ecb54ebfda0ab793
6
+ metadata.gz: 8f28511356f7d3208fa36abae71442333547e77766c820a657819ef2c75a2121627c0bdd2677bd8dd76cc5a1b01a3c16d7ab51fffc761568622462fb0fdcd5ec
7
+ data.tar.gz: 79a3f03044697f63340e29db2199acc0f494352db9b9bcb322fcff5592c4aa3423997c8e5ce0288642727dd5be3a24ff15481cc350a45584809162290a028e9d
@@ -36,11 +36,19 @@ module Fastlane
36
36
  end
37
37
 
38
38
  client = DropboxApi::Client.new(access_token)
39
+ fileSize = File.size(file_path)
40
+ more_space = is_space_enough(client, fileSize)
41
+ if more_space >= 0
42
+ UI.message 'space is enough'
43
+ else
44
+ UI.message "space almost fill need more #{-more_space}, delete the earliest file"
45
+ delete_earliest_file(client, -more_space)
46
+ end
39
47
 
40
48
  output_file = nil
41
49
  chunk_size = 157_286_400 # 150M
42
50
  destination_path = destination_path(dropbox_path, file_path)
43
- if File.size(file_path) < chunk_size
51
+ if fileSize < chunk_size
44
52
  output_file = upload(client, file_path, destination_path, write_mode)
45
53
  else
46
54
  output_file = upload_chunked(client, chunk_size, file_path, destination_path, write_mode)
@@ -106,6 +114,85 @@ module Fastlane
106
114
  parts
107
115
  end
108
116
 
117
+ def self.is_space_enough(client, fileSize)
118
+ spaceUsage = client.get_space_usage
119
+ used = spaceUsage.used.to_i
120
+ allocated = spaceUsage.allocation.allocated
121
+ unuse = allocated - used
122
+ UI.important "Space allocated: #{allocated} used: #{used} unuse: #{unuse} "
123
+ if fileSize > allocated
124
+ UI.user_error! 'Upload file size over allocated space'
125
+ end
126
+ return unuse - fileSize
127
+ end
128
+
129
+ def self.delete_earliest_file(client, more_space)
130
+ UI.message ''
131
+ UI.important "Need space #{more_space}"
132
+ UI.message ''
133
+ delete_space = 0
134
+ files = get_all_files(client)
135
+ files.each { |file|
136
+ delete_space = delete_space + delete_file(client, file)
137
+ if delete_space > more_space
138
+ break
139
+ end
140
+ }
141
+ UI.important "Delete space #{delete_space}"
142
+ end
143
+
144
+ def self.delete_file(client, file)
145
+ path_display = file.path_display
146
+ delete_result = client.delete path_display
147
+ UI.message "Delete file:#{file.path_display} size:#{file.size}"
148
+ return delete_result.size
149
+ end
150
+
151
+ def self.get_all_files(client)
152
+ files = list_folder(client)
153
+ files.sort_by { |a|
154
+ a.client_modified
155
+ }
156
+ return files
157
+ end
158
+
159
+ def self.list_folder(client, path = '')
160
+ UI.important "List files in path #{path} "
161
+ options = {}
162
+ options[:recursive] = true
163
+ options[:include_media_info] = false
164
+ options[:include_deleted] = false
165
+ folderResult = client.list_folder path, options
166
+ files = get_tagfile(folderResult)
167
+ if folderResult.has_more?
168
+ more_files = list_folder_continue(client, folderResult.cursor)
169
+ files.concat(more_files)
170
+ end
171
+ return files
172
+ end
173
+
174
+ def self.list_folder_continue(client, cursor)
175
+ folderResult = client.list_folder_continue cursor
176
+ files = get_tagfile(folderResult)
177
+ if folderResult.has_more?
178
+ more_files = list_folder_continue(client, folderResult.cursor)
179
+ files.concat(more_files)
180
+ end
181
+ return files
182
+ end
183
+
184
+ def self.get_tagfile(result)
185
+ files = []
186
+ entries = result.entries
187
+ entries[1..entries.size].each do |obj|
188
+ if obj.class == DropboxApi::Metadata::File
189
+ files.push(obj)
190
+ UI.message "File:#{obj.path_display} size:#{obj.size}"
191
+ end
192
+ end
193
+ return files
194
+ end
195
+
109
196
  def self.description
110
197
  "upload files to dropbox"
111
198
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module DropboxUpload
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-dropbox_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jason
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dropbox_api