Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATA-3698: fix weird file path behavior with export #4777

Merged
merged 3 commits into from
Feb 6, 2025
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
7 changes: 5 additions & 2 deletions cli/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -47,6 +48,8 @@ const (
noExistingADFErrCode = "NotFound"
)

var viamCaptureSubdirPattern = regexp.MustCompile(`.*` + viamCaptureDotSubdir)

type commonFilterArgs struct {
OrgIDs []string
LocationIDs []string
Expand Down Expand Up @@ -670,10 +673,10 @@ func filenameForDownload(meta *datapb.BinaryMetadata) string {
}

// If the file name is not a data capture file but was manually saved in the default viam capture directory, remove
// that directory. Otherwise, the file will be hidden due to the .viam directory.
// that directory + home directories. Otherwise, the file will be hidden due to the .viam directory.
// Use ReplaceAll rather than TrimPrefix since it will be stored under os.Getenv("HOME"), which differs between upload
// to export time.
fileName = strings.ReplaceAll(fileName, viamCaptureDotSubdir, "")
fileName = viamCaptureSubdirPattern.ReplaceAllString(fileName, "")

// The file name will end with .gz if the user uploaded a gzipped file. We will unzip it below, so remove the last
// .gz from the file name. If the user has gzipped the file multiple times, we will only unzip once.
Expand Down
6 changes: 6 additions & 0 deletions cli/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func TestFilenameForDownload(t *testing.T) {
inViamCaptureFolder := filenameForDownload(&datapb.BinaryMetadata{FileName: "/.viam/capture/2024-01-30Twhatever.jpg"})
test.That(t, inViamCaptureFolder, test.ShouldEqual, "2024-01-30Twhatever.jpg")

nestedViamCaptureFolder := filenameForDownload(&datapb.BinaryMetadata{FileName: "Users/hi/.viam/capture/2024-01-30Twhatever.jpg"})
test.That(t, nestedViamCaptureFolder, test.ShouldEqual, "2024-01-30Twhatever.jpg")

nestedDirViamCaptureFolder := filenameForDownload(&datapb.BinaryMetadata{FileName: "Users/hi/.viam/capture/dir/2024-01-30Twhatever.jpg"})
test.That(t, nestedDirViamCaptureFolder, test.ShouldEqual, "dir/2024-01-30Twhatever.jpg")

gzAtRoot := filenameForDownload(&datapb.BinaryMetadata{FileName: "whatever.gz"})
test.That(t, gzAtRoot, test.ShouldEqual, expectedUTC+"_whatever")

Expand Down
Loading