-
Notifications
You must be signed in to change notification settings - Fork 565
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
1 parent
efd1619
commit 8d4d735
Showing
8 changed files
with
13 additions
and
42 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
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
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
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 |
---|---|---|
@@ -1,40 +1,9 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const CACHEDIR_PERMISSION = 0755 | ||
|
||
// The directory structure used to cache things into | ||
// - Base cache directory (user definable, default depends on OS, exmple: /Users/username/Library/Caches/snyk/) | ||
// |- Version cache directory (example: /Users/username/Library/Caches/snyk/snyk-cli/1.1075.0/) | ||
// |- Temp directory (example: /Users/username/Library/Caches/snyk/snyk-cli/1.1075.0/tmp/) | ||
|
||
func GetTemporaryDirectory(baseCacheDirectory string, versionNumber string) string { | ||
pid := os.Getpid() | ||
return path.Join(GetVersionCacheDirectory(baseCacheDirectory, versionNumber), "tmp", fmt.Sprintf("pid%d", pid)) | ||
} | ||
|
||
func GetVersionCacheDirectory(baseCacheDirectory string, versionNumber string) string { | ||
return path.Join(baseCacheDirectory, versionNumber) | ||
} | ||
|
||
func CreateAllDirectories(baseCacheDirectory string, versionNumber string) error { | ||
directoryList := []string{ | ||
GetTemporaryDirectory(baseCacheDirectory, versionNumber), | ||
} | ||
|
||
for _, dir := range directoryList { | ||
err := os.MkdirAll(dir, CACHEDIR_PERMISSION) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create all directories.") | ||
} | ||
} | ||
|
||
return nil | ||
} |
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