Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .github/integration/tests/40_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ for filepath in $filepaths; do
fi
done

# Try to download files again using the -continue flag
testContinue=$(./sda-cli -config testing/s3cmd-download.conf download -pubkey user_key.pub.pem -dataset-id https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080 -outdir download-dataset --dataset -continue | grep -c Skipping)

# Check if all existing files were skipped
if [ "$testContinue" -ne 3 ]; then
echo "Failed to skip already existing files when using the -continue flag"
exit 1
fi

# Remove one file and try to download dataset again using the -continue flag
testContinueFilePath=download-dataset/main/subfolder/dummy_data.c4gh
rm "$testContinueFilePath"
testContinue=$(./sda-cli -config testing/s3cmd-download.conf download -pubkey user_key.pub.pem -dataset-id https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080 -outdir download-dataset --dataset -continue | grep -c Skipping)

# Check that only the existing files were skipped and the non-existing file was downloaded
if [ "$testContinue" -ne 2 ] || [ ! -f "$testContinueFilePath" ]; then
echo "Failed to download non-existing file when using the -continue flag"
exit 1
fi

rm -r download-dataset

# Download encrypted file by using the sda-cli download command
Expand Down
12 changes: 12 additions & 0 deletions download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Required options:
-url <uri> The url of the download server.

Optional options:
-continue Skip already downloaded files and continue with downloading the rest.
-pubkey <public-key-file> Key to use for encrypting downloaded files server-side.
This key must be given here or in the config file.
-outdir <dir> Directory to save the downloaded files.
Expand Down Expand Up @@ -78,6 +79,8 @@ var fromFile = Args.Bool("from-file", false, "Download files from file list.")

var pubKeyBase64 string

var continueDownload = Args.Bool("continue", false, "Skip existing files and continue with the rest.")

// necessary for mocking in testing
var getResponseBody = getBody

Expand Down Expand Up @@ -327,6 +330,15 @@ func downloadFile(uri, token, pubKeyBase64, filePath string) error {
if pubKeyBase64 != "" {
filePath += ".c4gh"
}

if *continueDownload {
if _, err := os.Stat(filePath); !errors.Is(err, os.ErrNotExist) {
fmt.Printf("Skipping download to %s, file already exists\n", filePath)

return nil
}
}
Comment thread
jbygdell marked this conversation as resolved.

outfile, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("failed to create file, reason: %v", err)
Expand Down
Loading