Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 7fbffe6

Browse files
authored
Merge pull request #62 from mnottale/extract-same-name
extract: extract to a subdir with same name as source.
2 parents dc2e751 + b756a38 commit 7fbffe6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packager/extract.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ func Extract(appname string) (string, func(), error) {
5656
return "", nil, err
5757
}
5858
}
59+
if appname == "." {
60+
var err error
61+
if appname, err = os.Getwd(); err != nil {
62+
return "", nil, errors.Wrap(err, "cannot resolve current working directory")
63+
}
64+
}
5965
// try verbatim first
6066
s, err := os.Stat(appname)
6167
if err != nil {
@@ -75,10 +81,16 @@ func Extract(appname string) (string, func(), error) {
7581
if err != nil {
7682
return "", noop, err
7783
}
78-
if err = extract(appname, tempDir); err != nil {
84+
appDir := filepath.Join(tempDir, filepath.Base(appname))
85+
if err := os.Mkdir(appDir, 0755); err != nil {
86+
os.RemoveAll(tempDir)
87+
return "", noop, err
88+
}
89+
if err = extract(appname, appDir); err != nil {
90+
os.RemoveAll(tempDir)
7991
return "", noop, err
8092
}
81-
return tempDir, func() { os.RemoveAll(tempDir) }, nil
93+
return appDir, func() { os.RemoveAll(tempDir) }, nil
8294
}
8395

8496
func extract(appname, outputDir string) error {

0 commit comments

Comments
 (0)