Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit a44c8d2

Browse files
authored
Convert path seperator on Windows (fix #313) (#315)
1 parent 4c1cf1c commit a44c8d2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

archiver.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,22 @@ func (f File) Stat() (fs.FileInfo, error) { return f.FileInfo, nil }
4343

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

77-
nameInArchive := path.Join(rootInArchive, strings.TrimPrefix(filename, rootOnDisk))
83+
truncPath := strings.TrimPrefix(filename, rootOnDisk)
84+
nameInArchive := path.Join(rootInArchive, filepath.ToSlash(truncPath))
7885
var linkTarget string
7986

8087
if isSymlink(info) {

0 commit comments

Comments
 (0)