Skip to content

Commit

Permalink
B2 backend should be able to download .fsl files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gilbertchen committed Mar 30, 2023
1 parent 53b0f3f commit 1f9ad0e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/duplicacy_b2client.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (client *B2Client) AuthorizeAccount(threadIndex int) (err error, allowed bo
if client.DownloadURL == "" {
client.DownloadURL = output.DownloadURL
}
LOG_INFO("BACKBLAZE_URL", "download URL is: %s", client.DownloadURL)
LOG_INFO("BACKBLAZE_URL", "Download URL is: %s", client.DownloadURL)
client.IsAuthorized = true

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

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

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

readCloser, _, len, err := client.call(threadIndex, url, http.MethodGet, make(map[string]string), 0)
return readCloser, len, err
}

// We're trying to download a fossil file. We need to find the file ID of the last 'upload' of the file.
filePath = strings.TrimSuffix(filePath, ".fsl")
entries, err := client.ListFileNames(threadIndex, filePath, true, true)
fileId := ""
for _, entry := range entries {
if entry.FileName == filePath && entry.Action == "upload" && entry.Size > 0 {
fileId = entry.FileID
break
}
}

// Proceed with the b2_download_file_by_id call
url := client.getAPIURL() + "/b2api/v1/b2_download_file_by_id?fileId=" + fileId
readCloser, _, len, err := client.call(threadIndex, url, http.MethodGet, make(map[string]string), 0)
return readCloser, len, err
}
Expand Down

4 comments on commit 1f9ad0e

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/error-finding-fsl-on-b2/7470/3

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/cli-release-3-2-0-is-now-available/7952/1

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/duplicacy-cli-3-2-2-release/8019/1

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/file-not-found-how-do-i-start-from-scratch/8484/9

Please sign in to comment.