Skip to content

Commit 1f9ad0e

Browse files
committed
B2 backend should be able to download .fsl files
This is needed when a metadata chunk has been turned into a fossil. In B2, the fossil file is the last version of the file with an 'upload' action, so to download the file, the 'b2_list_file_versions' api is called to find the file id and then download it using 'b2_download_file_by_id'. This is needed when a metadata chunk has been turned into a fossil
1 parent 53b0f3f commit 1f9ad0e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/duplicacy_b2client.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (client *B2Client) AuthorizeAccount(threadIndex int) (err error, allowed bo
329329
if client.DownloadURL == "" {
330330
client.DownloadURL = output.DownloadURL
331331
}
332-
LOG_INFO("BACKBLAZE_URL", "download URL is: %s", client.DownloadURL)
332+
LOG_INFO("BACKBLAZE_URL", "Download URL is: %s", client.DownloadURL)
333333
client.IsAuthorized = true
334334

335335
client.LastAuthorizationTime = time.Now().Unix()
@@ -584,8 +584,26 @@ func (client *B2Client) HideFile(threadIndex int, fileName string) (fileID strin
584584

585585
func (client *B2Client) DownloadFile(threadIndex int, filePath string) (io.ReadCloser, int64, error) {
586586

587-
url := client.getDownloadURL() + "/file/" + client.BucketName + "/" + B2Escape(client.StorageDir + filePath)
587+
if !strings.HasSuffix(filePath, ".fsl") {
588+
url := client.getDownloadURL() + "/file/" + client.BucketName + "/" + B2Escape(client.StorageDir + filePath)
588589

590+
readCloser, _, len, err := client.call(threadIndex, url, http.MethodGet, make(map[string]string), 0)
591+
return readCloser, len, err
592+
}
593+
594+
// We're trying to download a fossil file. We need to find the file ID of the last 'upload' of the file.
595+
filePath = strings.TrimSuffix(filePath, ".fsl")
596+
entries, err := client.ListFileNames(threadIndex, filePath, true, true)
597+
fileId := ""
598+
for _, entry := range entries {
599+
if entry.FileName == filePath && entry.Action == "upload" && entry.Size > 0 {
600+
fileId = entry.FileID
601+
break
602+
}
603+
}
604+
605+
// Proceed with the b2_download_file_by_id call
606+
url := client.getAPIURL() + "/b2api/v1/b2_download_file_by_id?fileId=" + fileId
589607
readCloser, _, len, err := client.call(threadIndex, url, http.MethodGet, make(map[string]string), 0)
590608
return readCloser, len, err
591609
}

0 commit comments

Comments
 (0)