Skip to content

Commit

Permalink
Convert path seperator on Windows (fix #313) (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 21, 2022
1 parent 4c1cf1c commit a44c8d2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions archiver.go
Expand Up @@ -43,16 +43,22 @@ func (f File) Stat() (fs.FileInfo, error) { return f.FileInfo, nil }

// FilesFromDisk returns a list of files by walking the directories in the
// given filenames map. The keys are the names on disk, and the values are
// their associated names in the archive. For convenience, empty values are
// interpreted as the base name of the file (sans path) in the root of the
// archive; and values that end in a slash will use the bae name of the file
// in that folder of the archive. Keys that specify directories on disk will
// be walked and added to the archive recursively, rooted at the named
// directory.
// their associated names in the archive.
//
// Map keys that specify directories on disk will be walked and added to the
// archive recursively, rooted at the named directory. They should use the
// platform's path separator (backslash on Windows; slash on everything else).
//
// Map values should typically use slash ('/') as the separator regardless of
// the platform, as most archive formats standardize on that rune as the
// directory separator for filenames within an archive. For convenience, map
// values that are empty string are interpreted as the base name of the file
// (sans path) in the root of the archive; and map values that end in a slash
// will use the base name of the file in that folder of the archive.
//
// File gathering will adhere to the settings specified in options.
//
// This function is primarily used when preparing a list of files to add to
// This function is used primarily when preparing a list of files to add to
// an archive.
func FilesFromDisk(options *FromDiskOptions, filenames map[string]string) ([]File, error) {
var files []File
Expand All @@ -74,7 +80,8 @@ func FilesFromDisk(options *FromDiskOptions, filenames map[string]string) ([]Fil
return err
}

nameInArchive := path.Join(rootInArchive, strings.TrimPrefix(filename, rootOnDisk))
truncPath := strings.TrimPrefix(filename, rootOnDisk)
nameInArchive := path.Join(rootInArchive, filepath.ToSlash(truncPath))
var linkTarget string

if isSymlink(info) {
Expand Down

0 comments on commit a44c8d2

Please sign in to comment.