rb1drv 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rb1drv/onedrive_404.rb +4 -0
- data/lib/rb1drv/onedrive_dir.rb +31 -25
- data/lib/rb1drv/onedrive_file.rb +18 -0
- data/lib/rb1drv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 441718671c6e794189827b5411f9d3081931dbf9b5f9b8a1b1eaad8ebfd7487b
|
4
|
+
data.tar.gz: 9dac61af7d31703a8b90288a435f54aa4681464e6598a6818f49bac77dd0cea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f2da5b24a15baecef1b3e9a0cbe99b481792a66fc1eaed1280904543db09dc131ca9bb20feb49c274d790168f17c7a2e3d17aa10c1e76c7a34924e47b88b26
|
7
|
+
data.tar.gz: cadf55833889484e9856585bde0fe794ed6ed9dcdd124658502cea266e4e8cf2c621197db1504e71355a4c6eb3255dd58fae6fc08ccd0f2f9b859e74a1da68cf
|
data/Gemfile.lock
CHANGED
data/lib/rb1drv/onedrive_404.rb
CHANGED
data/lib/rb1drv/onedrive_dir.rb
CHANGED
@@ -15,7 +15,7 @@ module Rb1drv
|
|
15
15
|
# @return [Array<OneDriveDir,OneDriveFile>] directories and files whose parent is current directory
|
16
16
|
def children
|
17
17
|
return [] if child_count <= 0
|
18
|
-
@cached_children ||= @od.request("#{api_path}/children")['value'].map do |child|
|
18
|
+
@cached_children ||= @od.request("#{api_path}/children?$top=1000")['value'].map do |child|
|
19
19
|
OneDriveItem.smart_new(@od, child)
|
20
20
|
end
|
21
21
|
end
|
@@ -110,6 +110,8 @@ module Rb1drv
|
|
110
110
|
|
111
111
|
resume_file = "#{filename}.1drv_upload"
|
112
112
|
resume_session = JSON.parse(File.read(resume_file)) rescue nil if File.exist?(resume_file)
|
113
|
+
old_file = OneDriveItem.smart_new(@od, @od.request("#{api_path}:/#{target_name}"))
|
114
|
+
new_file = nil
|
113
115
|
|
114
116
|
result = nil
|
115
117
|
loop do
|
@@ -132,14 +134,17 @@ module Rb1drv
|
|
132
134
|
|
133
135
|
until resume_session && resume_session['session_url'] do
|
134
136
|
result = @od.request("#{api_path}:/#{target_name}:/createUploadSession", item: {'@microsoft.graph.conflictBehavior': overwrite ? 'replace' : 'rename'})
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
137
|
+
if result['uploadUrl']
|
138
|
+
resume_session = {
|
139
|
+
'session_url' => result['uploadUrl'],
|
140
|
+
'source_size' => File.size(filename),
|
141
|
+
'fragment_size' => fragment_size
|
142
|
+
}
|
143
|
+
File.write(resume_file, JSON.pretty_generate(resume_session))
|
144
|
+
conn = Excon.new(resume_session['session_url'], idempotent: true)
|
145
|
+
break
|
146
|
+
end
|
147
|
+
sleep 15
|
143
148
|
end
|
144
149
|
|
145
150
|
new_file = nil
|
@@ -157,31 +162,36 @@ module Rb1drv
|
|
157
162
|
yield :progress, file: filename, from: from, to: to, progress: progress, total: total if block_given?
|
158
163
|
end
|
159
164
|
begin
|
160
|
-
result = conn.put headers: headers, chunk_size: chunk_size, body: sliced_io,
|
165
|
+
result = conn.put headers: headers, chunk_size: chunk_size, body: sliced_io, retry_limit: 2
|
161
166
|
raise IOError if result.body.include? 'accessDenied'
|
162
|
-
rescue Excon::Error::
|
167
|
+
rescue Excon::Error::Socket, IOError
|
168
|
+
# Probably server rejected this request
|
169
|
+
throw :restart
|
170
|
+
rescue Excon::Error::Timeout
|
163
171
|
conn = Excon.new(resume_session['session_url'], idempotent: true)
|
164
172
|
yield :retry, file: filename, from: from, to: to if block_given?
|
165
173
|
retry
|
166
|
-
|
167
|
-
|
168
|
-
yield :retry, file: filename, from: from, to: to if block_given?
|
169
|
-
sleep 60
|
170
|
-
retry
|
174
|
+
ensure
|
175
|
+
yield :finish_segment, file: filename, from: from, to: to if block_given?
|
171
176
|
end
|
172
|
-
yield :finish_segment, file: filename, from: from, to: to if block_given?
|
173
177
|
throw :restart if result.body.include?('</html>')
|
174
178
|
result = JSON.parse(result.body)
|
175
179
|
new_file = OneDriveFile.new(@od, result) if result.dig('file')
|
176
180
|
end
|
177
181
|
end
|
178
182
|
throw :restart unless new_file&.file?
|
179
|
-
|
180
|
-
return set_mtime(new_file, File.mtime(filename))
|
183
|
+
break
|
181
184
|
end
|
182
185
|
# catch :restart here
|
183
|
-
sleep 60 #
|
186
|
+
sleep 60 # wait for server to process the previous request
|
187
|
+
new_file = OneDriveItem.smart_new(@od, @od.request("#{api_path}:/#{target_name}"))
|
188
|
+
break if new_file.file? && new_file.id != old_file.id
|
189
|
+
# and retry the whole process
|
184
190
|
end
|
191
|
+
|
192
|
+
# upload completed
|
193
|
+
File.unlink(resume_file)
|
194
|
+
return new_file.set_mtime(File.mtime(filename))
|
185
195
|
end
|
186
196
|
|
187
197
|
# Uploads a local file into current remote directory using simple upload mode.
|
@@ -209,11 +219,7 @@ module Rb1drv
|
|
209
219
|
result = @od.conn.put(query)
|
210
220
|
result = JSON.parse(result.body)
|
211
221
|
file = OneDriveFile.new(@od, result)
|
212
|
-
set_mtime(
|
213
|
-
end
|
214
|
-
|
215
|
-
def set_mtime(file, time)
|
216
|
-
OneDriveFile.new(@od, @od.request(file.api_path, {fileSystemInfo: {lastModifiedDateTime: time.utc.iso8601}}, :patch))
|
222
|
+
file.set_mtime(File.mtime(filename))
|
217
223
|
end
|
218
224
|
end
|
219
225
|
end
|
data/lib/rb1drv/onedrive_file.rb
CHANGED
@@ -57,5 +57,23 @@ module Rb1drv
|
|
57
57
|
yield :finish_segment, file: target_name if block_given?
|
58
58
|
FileUtils.mv(tmpfile, filename)
|
59
59
|
end
|
60
|
+
|
61
|
+
# Change last modified time for a remote file.
|
62
|
+
#
|
63
|
+
# NOTICE: OneDrive by default keeps multiple history version for this operation.
|
64
|
+
# NOTICE: You must turn off versioning to prevent multiple counts on disk quota.
|
65
|
+
#
|
66
|
+
# 3 attempts will be made due to delay after a file upload.
|
67
|
+
#
|
68
|
+
# @param time [Time] desired last modified time
|
69
|
+
# @return [OneDriveFile] new file object returned by API
|
70
|
+
def set_mtime(time)
|
71
|
+
attempt = 0
|
72
|
+
OneDriveFile.new(@od, @od.request(api_path, {fileSystemInfo: {lastModifiedDateTime: time.utc.iso8601}}, :patch))
|
73
|
+
rescue
|
74
|
+
sleep 10
|
75
|
+
attempt += 1
|
76
|
+
retry if attempt <= 3
|
77
|
+
end
|
60
78
|
end
|
61
79
|
end
|
data/lib/rb1drv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb1drv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xinyue Lu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|