Skip to content

Commit

Permalink
DATA-3698: fix weird file path behavior with export (viamrobotics#4777)
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriacai01 authored and vijayvuyyuru committed Feb 11, 2025
1 parent a989251 commit c0acb0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit c0acb0c

Please sign in to comment.