Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/duplicacy_backupmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
var numberOfNewFileChunks int64 // number of new file chunks
var totalUploadedFileChunkLength int64 // total length of uploaded file chunks
var totalUploadedFileChunkBytes int64 // how many actual bytes have been uploaded
var addDataErr string // error string from fileChunkMaker.AddData()

// This function is called when a chunk has been uploaded
uploadChunkCompletionFunc := func(chunk *Chunk, chunkIndex int, inCache bool, chunkSize int, uploadSize int) {
Expand Down Expand Up @@ -479,8 +480,11 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
skippedFiles = append(skippedFiles, entry.Path)
continue
}
entry.Size, entry.Hash = fileChunkMaker.AddData(file, uploadChunkFunc)
if !showStatistics || IsTracing() || RunInBackground {

entry.Size, entry.Hash, addDataErr = fileChunkMaker.AddData(file, uploadChunkFunc)
if entry.Size <= 0 && addDataErr == "CLOUD_FILE_FAILURE" {
skippedFiles = append(skippedFiles, entry.Path)
} else if !showStatistics || IsTracing() || RunInBackground {
LOG_INFO("PACK_END", "Packed %s (%d)", entry.Path, entry.Size)
}
file.Close()
Expand Down
29 changes: 18 additions & 11 deletions src/duplicacy_chunkmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"encoding/binary"
"encoding/hex"
"io"
"runtime"
"strings"
)

// ChunkMaker breaks data into chunks using buzhash. To save memory, the chunk maker only use a circular buffer
Expand Down Expand Up @@ -135,7 +137,7 @@ func (maker *ChunkMaker) startNewChunk() (chunk *Chunk) {
return
}

func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int64, string) {
func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int64, string, string) {

isEOF := false
fileSize := int64(0)
Expand All @@ -161,7 +163,7 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
if maker.minimumChunkSize == maker.maximumChunkSize {

if reader == nil {
return 0, ""
return 0, "", ""
}

for {
Expand All @@ -172,8 +174,11 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6

if err != nil {
if err != io.EOF {
LOG_ERROR("CHUNK_MAKER", "Failed to read %d bytes: %s", count, err.Error())
return 0, ""
// handle OneDrive 'cloud files' errors (sometimes these are caught by os.OpenFile, sometimes
// not)
isWarning := runtime.GOOS == "windows" && strings.HasSuffix(err.Error(), " Access to the cloud file is denied.")
LOG_WERROR(isWarning, "CHUNK_MAKER", "Failed to read %d bytes: %s", count, err.Error())
return -1, "", "CLOUD_FILE_FAILURE" // we'd only hit this if it was a cloud file warning, LOG_ERROR panic exits
} else {
isEOF = true
}
Expand All @@ -189,7 +194,7 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
}

if isEOF {
return fileSize, hex.EncodeToString(fileHasher.Sum(nil))
return fileSize, hex.EncodeToString(fileHasher.Sum(nil)), ""
}
}

Expand All @@ -209,8 +214,10 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
count, err = reader.Read(maker.buffer[start : start+count])

if err != nil && err != io.EOF {
LOG_ERROR("CHUNK_MAKER", "Failed to read %d bytes: %s", count, err.Error())
return 0, ""
// handle OneDrive 'cloud files' errors (sometimes these are caught by os.OpenFile, sometimes not)
isWarning := runtime.GOOS == "windows" && strings.HasSuffix(err.Error(), " Access to the cloud file is denied.")
LOG_WERROR(isWarning, "CHUNK_MAKER", "Failed to read %d bytes: %s", count, err.Error())
return -1, "", "CLOUD_FILE_FAILURE" // we'd only hit this if it was a cloud file warning, LOG_ERROR panic exits
}

maker.bufferSize += count
Expand All @@ -231,9 +238,9 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
if maker.chunk.GetLength() > 0 {
sendChunk(maker.chunk)
}
return 0, ""
return 0, "", ""
} else if isEOF {
return fileSize, hex.EncodeToString(fileHasher.Sum(nil))
return fileSize, hex.EncodeToString(fileHasher.Sum(nil)), ""
} else {
continue
}
Expand Down Expand Up @@ -295,12 +302,12 @@ func (maker *ChunkMaker) AddData(reader io.Reader, sendChunk func(*Chunk)) (int6
fill(maker.minimumChunkSize)
sendChunk(maker.chunk)
maker.startNewChunk()
return 0, ""
return 0, "", ""
}
}

if isEOF {
return fileSize, hex.EncodeToString(fileHasher.Sum(nil))
return fileSize, hex.EncodeToString(fileHasher.Sum(nil)), ""
}
}
}