-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
125 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package rpc | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/projecteru2/core/utils" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func cleanDumpFiles(data map[string]string) error { | ||
log.Debugf("[cleanDumpFiles] clean dump files %v", data) | ||
var err error | ||
for _, src := range data { | ||
if err = os.RemoveAll(src); err != nil { | ||
log.Errorf("[cleanDumpFiles] clean dump files failed %v", err) | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func withDumpFiles(data map[string][]byte, f func(files map[string]string) error) error { | ||
files := map[string]string{} | ||
for path, data := range data { | ||
fname, err := utils.TempTarFile(path, data) | ||
if err != nil { | ||
defer func() { | ||
os.RemoveAll(fname) | ||
for p := range files { | ||
os.RemoveAll(p) | ||
} | ||
}() | ||
return err | ||
} | ||
files[path] = fname | ||
} | ||
log.Debugf("[withDumpFiles] with temp files %v", files) | ||
defer cleanDumpFiles(files) | ||
return f(files) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters