Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Issue warning about files with slashes for 'skicka download'
Browse files Browse the repository at this point in the history
Drive allows file names to have slashes in them, and skicka doesn't handle
these files well. Previously, downloads would silently ignore these files,
which posed the risk of losing data; now at least we issue a warning about
each such file during downloads.

Issue #89.
  • Loading branch information
Matt Pharr committed Feb 10, 2016
1 parent 7560452 commit a4534b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func syncHierarchyDown(driveBasePath string, localBasePath string, trustTimes bo
uniqueDriveFiles = files
}

// Warn that we're going to ignore any files that have slashes in their
// names.
var files []*gdrive.File
for _, f := range uniqueDriveFiles {
if f.PathHasSlash() {
message("%s: skipping file with slash in filename", f.Path)
} else {
files = append(files, f)
}
}
uniqueDriveFiles = files

// Create a map that stores the local filename to use for each file in
// Google Drive. This map is indexed by the path of the Google Drive
// file.
Expand Down
12 changes: 11 additions & 1 deletion gdrive/gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const metadataVersion = 2
type File struct {
// Path name on Drive. Does not start with a slash.
Path string
// Indicates whether the original file name in Drive had a slash in it.
pathHasSlash bool
// Size of the file in bytes.
FileSize int64
// Unique id of the file (that persists over file modifications,
Expand Down Expand Up @@ -137,6 +139,10 @@ func (f *File) driveFile() *drive.File {
}
}

func (f *File) PathHasSlash() bool {
return f.pathHasSlash
}

// IsFolder returns a boolean indicating whether the given File is a
// folder.
func (f *File) IsFolder() bool {
Expand Down Expand Up @@ -559,11 +565,15 @@ func (gd *GDrive) UpdateMetadataCache(filename string) error {
// declaration for an issue with this approach, though.
file := new(File)
*file = *f
file.pathHasSlash = strings.ContainsRune(f.Path, '/')
file.Path = p

gd.pathToFile[p] = append(gd.pathToFile[p], file)

dir := filepath.Dir(p)
// Explicitly trim off the file's name to get the path, rather
// than using filepath.Dir(), so that if there is a slash in
// the filename, we still get the expected result.
dir := filepath.Clean(strings.TrimSuffix(p, f.Path))
gd.dirToFiles[dir] = append(gd.dirToFiles[dir], file)

if f.IsFolder() {
Expand Down

0 comments on commit a4534b4

Please sign in to comment.