9
9
"encoding/binary"
10
10
"encoding/hex"
11
11
"io"
12
+ "runtime"
13
+ "strings"
12
14
)
13
15
14
16
// ChunkMaker breaks data into chunks using buzhash. To save memory, the chunk maker only use a circular buffer
@@ -135,7 +137,7 @@ func (maker *ChunkMaker) startNewChunk() (chunk *Chunk) {
135
137
return
136
138
}
137
139
138
- func (maker * ChunkMaker ) AddData (reader io.Reader , sendChunk func (* Chunk )) (int64 , string ) {
140
+ func (maker * ChunkMaker ) AddData (reader io.Reader , sendChunk func (* Chunk )) (int64 , string , string ) {
139
141
140
142
isEOF := false
141
143
fileSize := int64 (0 )
@@ -161,7 +163,7 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
161
163
if maker .minimumChunkSize == maker .maximumChunkSize {
162
164
163
165
if reader == nil {
164
- return 0 , ""
166
+ return 0 , "" , ""
165
167
}
166
168
167
169
for {
@@ -172,8 +174,11 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
172
174
173
175
if err != nil {
174
176
if err != io .EOF {
175
- LOG_ERROR ("CHUNK_MAKER" , "Failed to read %d bytes: %s" , count , err .Error ())
176
- return 0 , ""
177
+ // handle OneDrive 'cloud files' errors (sometimes these are caught by os.OpenFile, sometimes
178
+ // not)
179
+ isWarning := runtime .GOOS == "windows" && strings .HasSuffix (err .Error (), " Access to the cloud file is denied." )
180
+ LOG_WERROR (isWarning , "CHUNK_MAKER" , "Failed to read %d bytes: %s" , count , err .Error ())
181
+ return - 1 , "" , "CLOUD_FILE_FAILURE" // we'd only hit this if it was a cloud file warning, LOG_ERROR panic exits
177
182
} else {
178
183
isEOF = true
179
184
}
@@ -189,7 +194,7 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
189
194
}
190
195
191
196
if isEOF {
192
- return fileSize , hex .EncodeToString (fileHasher .Sum (nil ))
197
+ return fileSize , hex .EncodeToString (fileHasher .Sum (nil )), ""
193
198
}
194
199
}
195
200
@@ -209,8 +214,10 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
209
214
count , err = reader .Read (maker .buffer [start : start + count ])
210
215
211
216
if err != nil && err != io .EOF {
212
- LOG_ERROR ("CHUNK_MAKER" , "Failed to read %d bytes: %s" , count , err .Error ())
213
- return 0 , ""
217
+ // handle OneDrive 'cloud files' errors (sometimes these are caught by os.OpenFile, sometimes not)
218
+ isWarning := runtime .GOOS == "windows" && strings .HasSuffix (err .Error (), " Access to the cloud file is denied." )
219
+ LOG_WERROR (isWarning , "CHUNK_MAKER" , "Failed to read %d bytes: %s" , count , err .Error ())
220
+ return - 1 , "" , "CLOUD_FILE_FAILURE" // we'd only hit this if it was a cloud file warning, LOG_ERROR panic exits
214
221
}
215
222
216
223
maker .bufferSize += count
@@ -231,9 +238,9 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
231
238
if maker .chunk .GetLength () > 0 {
232
239
sendChunk (maker .chunk )
233
240
}
234
- return 0 , ""
241
+ return 0 , "" , ""
235
242
} else if isEOF {
236
- return fileSize , hex .EncodeToString (fileHasher .Sum (nil ))
243
+ return fileSize , hex .EncodeToString (fileHasher .Sum (nil )), ""
237
244
} else {
238
245
continue
239
246
}
@@ -295,12 +302,12 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
295
302
fill (maker .minimumChunkSize )
296
303
sendChunk (maker .chunk )
297
304
maker .startNewChunk ()
298
- return 0 , ""
305
+ return 0 , "" , ""
299
306
}
300
307
}
301
308
302
309
if isEOF {
303
- return fileSize , hex .EncodeToString (fileHasher .Sum (nil ))
310
+ return fileSize , hex .EncodeToString (fileHasher .Sum (nil )), ""
304
311
}
305
312
}
306
313
}
0 commit comments