Add comment
Debug dir cleanup
pull/158/head
Pagran 5 years ago
parent 3889fcdaab
commit b386489b1a

@ -71,9 +71,17 @@ func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error {
if envGarbleDebugDir == "" {
return nil
}
var archiveMember *goobj2.ArchiveMember
for _, member := range pkg.ArchiveMembers {
if member.ArchiveHeader.Name != garbleSrcHeaderName {
continue
if member.ArchiveHeader.Name == garbleSrcHeaderName {
archiveMember = &member
break
}
}
if archiveMember == nil {
return nil
}
osPkgPath := filepath.FromSlash(pkgPath)
@ -82,12 +90,12 @@ func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error {
return err
}
archiveSize, err := strconv.Atoi(member.ArchiveHeader.Date)
archiveSize, err := strconv.Atoi(archiveMember.ArchiveHeader.Date)
if err != nil {
return err
}
archiveBytes := member.ArchiveHeader.Data[:archiveSize]
archiveBytes := archiveMember.ArchiveHeader.Data[:archiveSize]
archive := bytes.NewBuffer(archiveBytes)
gzipReader, err := gzip.NewReader(archive)
@ -117,10 +125,12 @@ func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error {
debugFile.Close()
obfuscationTime := header.ModTime.Local()
os.Chtimes(debugFilePath, obfuscationTime, obfuscationTime) // Restore obfuscation time
// Restore the actual source obfuscation time so as not to mislead the user.
if err := os.Chtimes(debugFilePath, obfuscationTime, obfuscationTime); err != nil {
return err
}
}
return nil
}
// obfuscateImports does all the necessary work to replace the import paths of

@ -359,15 +359,13 @@ func mainErr(args []string) error {
flagDebugDir = filepath.Join(wd, flagDebugDir)
}
if info, err := os.Stat(flagDebugDir); os.IsNotExist(err) {
if err := os.RemoveAll(flagDebugDir); err == nil || os.IsNotExist(err) {
err := os.MkdirAll(flagDebugDir, 0o755)
if err != nil {
return err
}
} else if err != nil {
} else {
return fmt.Errorf("debugdir error: %v", err)
} else if !info.IsDir() {
return fmt.Errorf("debugdir exists, but is a file not a directory")
}
}
@ -781,7 +779,8 @@ func transformCompile(args []string) ([]string, error) {
ArchiveHeader: goobj2.ArchiveHeader{
Name: garbleSrcHeaderName,
Size: int64(obfSrcArchive.Len()),
Date: strconv.Itoa(obfSrcArchive.Len()), // Zero byte bug bypass
// Work around https://github.com/Binject/debug/issues/14
Date: strconv.Itoa(obfSrcArchive.Len()),
Data: obfSrcArchive.Bytes(),
},
})

@ -1,4 +1,6 @@
env GOPRIVATE=test/main
# Isolate go cache for test reproducibility
env GOCACHE=$WORK/.temp-cache
garble -debugdir ./test1 build
exists 'test1/test/main/imported/imported.go' 'test1/main/main.go'
@ -6,6 +8,14 @@ exists 'test1/test/main/imported/imported.go' 'test1/main/main.go'
! grep ImportedFunc $WORK/test1/main/main.go
! grep 'some comment' $WORK/test1/main/main.go
[short] stop
cp $WORK/test1/main/main.go $WORK/test1/some_file_from_prev_build.go
garble -debugdir ./test1 build -v
! stderr 'test/main'
! exists $WORK/test1/some_file_from_prev_build.go
-- go.mod --
module test/main
-- main.go --

Loading…
Cancel
Save