Skip to content

Commit

Permalink
Fix for invalid cross-device link (issue #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
9seconds committed Nov 2, 2014
1 parent 81dd9fb commit a0cf1de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/commands/tee.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Tee implements t (trace, tee) command.
func Tee(input string, interactive bool, pseudoTTY bool, env *environments.Environment) {
output, err := ioutil.TempFile(os.TempDir(), "ah")
output, err := ioutil.TempFile(env.GetTmpDir(), "ah")
if err != nil {
utils.Logger.Panic("Cannot create temporary file")
}
Expand All @@ -35,9 +35,12 @@ func Tee(input string, interactive bool, pseudoTTY bool, env *environments.Envir
output.Close()

if hash, err := getPreciseHash(input, env); err == nil {
err = os.Rename(output.Name(), env.GetTraceFileName(hash))
filename := env.GetTraceFileName(hash)
err = os.Rename(output.Name(), filename)
if err != nil {
utils.Logger.Errorf("Cannot save trace: %v. Get it here: %s", err, output.Name())
} else {
os.Remove(filename)
}
} else {
utils.Logger.Errorf("Error occured on fetching command number: %v", err)
Expand Down
8 changes: 8 additions & 0 deletions app/environments/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
defaultAppDir = ".ah"
tracesDir = "traces"
bookmarksDir = "bookmarks"
defaultTmpDir = "tmp"

defaultZshHistFile = ".zsh_history"
defaultBashHistFile = ".bash_history"
Expand Down Expand Up @@ -58,6 +59,13 @@ func (e *Environment) OK() bool {
return e.appDir != "" && e.histFile != "" && e.shell != ""
}

// GetTmpDir returns a path to temporary directory
// For the reason why it is required, please see this:
// https://github.com/9seconds/ah/issues/3
func (e *Environment) GetTmpDir() string {
return filepath.Join(e.appDir, defaultTmpDir)
}

// GetTracesDir returns an absolute path for the directory where traces should be stored.
func (e *Environment) GetTracesDir() string {
return filepath.Join(e.appDir, tracesDir)
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func main() {
utils.Logger.WithFields(logrus.Fields{
"error": os.MkdirAll(env.GetBookmarksDir(), 0777),
}).Info("Create bookmarks dir")
utils.Logger.WithFields(logrus.Fields{
"error": os.MkdirAll(env.GetTmpDir(), 0777),
}).Info("Create create temporary dir")

var exec executor
switch {
Expand Down

0 comments on commit a0cf1de

Please sign in to comment.