Skip to content

Commit

Permalink
[cache] Create various cache files in subfolders. [see issue #30]
Browse files Browse the repository at this point in the history
  • Loading branch information
cipriancraciun committed Oct 10, 2021
1 parent 6dada14 commit fd7b340
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
7 changes: 5 additions & 2 deletions sources/lib/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ func doHandleExecuteScriptletSsh (_library LibraryStore, _scriptlet *Scriptlet,
_sshCache = "/tmp"
}

if _error := makeCacheFolder (_context.cacheRoot, "ssh-sockets"); _error != nil {
return false, _error
}
if _sshLibraryLocalSocket == "" {
_sshLibraryLocalSocket = path.Join (_context.cacheRoot, fmt.Sprintf ("%s-%08x.sock", _sshToken, os.Getpid ()))
_sshLibraryLocalSocket = path.Join (_context.cacheRoot, "ssh-sockets", fmt.Sprintf ("%s-%08x.sock", _sshToken, os.Getpid ()))
}
if _sshLibraryRemoteSocket == "" {
_sshLibraryRemoteSocket = path.Join (_sshCache, fmt.Sprintf ("z-run--%s.sock", _sshToken))
Expand All @@ -308,7 +311,7 @@ func doHandleExecuteScriptletSsh (_library LibraryStore, _scriptlet *Scriptlet,
ExecutablePaths : _invokeExecutablePaths,
Terminal : _sshTerminal,
Workspace : _sshWorkspace,
Cache : _sshCache,
CacheRoot : _sshCache,
}

var _invokeContextEncoded string
Expand Down
20 changes: 15 additions & 5 deletions sources/lib/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,19 @@ func prepareExecution_0 (

case "<go>", "<go+>" :

if _error := makeCacheFolder (_contextCacheRoot, "go-root"); _error != nil {
return nil, nil, _error
}
if _error := makeCacheFolder (_contextCacheRoot, "go-sources"); _error != nil {
return nil, nil, _error
}
if _error := makeCacheFolder (_contextCacheRoot, "go-executables"); _error != nil {
return nil, nil, _error
}

_goFingerprint := _scriptletFingerprint
_goSource := path.Join (_contextCacheRoot, _goFingerprint + ".go")
_goExecutable := path.Join (_contextCacheRoot, _goFingerprint + ".exec")
_goSource := path.Join (_contextCacheRoot, "go-sources", _goFingerprint + ".go")
_goExecutable := path.Join (_contextCacheRoot, "go-executables", _goFingerprint + ".exec")

if _, _error := os.Stat (_goExecutable); _error == nil {
// PASS
Expand Down Expand Up @@ -419,17 +429,17 @@ func prepareExecution_0 (
_interpreterScriptBuffer.WriteString (_scriptletBody)
}

_goSourceTmp := path.Join (_contextCacheRoot, generateRandomToken () + ".tmp")
_goSourceTmp := path.Join (_contextCacheRoot, "go-sources", generateRandomToken () + ".tmp")
if _error := os.WriteFile (_goSourceTmp, _interpreterScriptBuffer.Bytes (), 0600); _error != nil {
return nil, nil, errorw (0x55976c12, _error)
}
if _error := os.Rename (_goSourceTmp, _goSource); _error != nil {
return nil, nil, errorw (0x5367f11a, _error)
}

_goExecutableTmp := path.Join (_contextCacheRoot, generateRandomToken () + ".tmp")
_goExecutableTmp := path.Join (_contextCacheRoot, "go-executables", generateRandomToken () + ".tmp")

_goRoot := path.Join (_contextCacheRoot, "go")
_goRoot := path.Join (_contextCacheRoot, "go-root")
_goCache := path.Join (_goRoot, "cache")
_goTmp := path.Join (_goRoot, "tmp")
for _, _mkdirPath := range []string { _goRoot, _goCache, _goTmp } {
Expand Down
4 changes: 2 additions & 2 deletions sources/lib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type InvokeContext struct {
ExecutablePaths []string `json:"executable-paths,omitempty"`
Terminal string `json:"terminal,omitempty"`
Workspace string `json:"workspace,omitempty"`
Cache string `json:"cache,omitempty"`
CacheRoot string `json:"cache-root,omitempty"`
}


Expand Down Expand Up @@ -409,7 +409,7 @@ func Main (_executable string, _argument0 string, _arguments []string, _environm
_terminal = _context.Terminal
_libraryCacheUrl = _context.Library
_workspace = _context.Workspace
_cacheRoot = _context.Cache
_cacheRoot = _context.CacheRoot
_top = false
}

Expand Down
5 changes: 4 additions & 1 deletion sources/lib/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func parseLibrary (_sources []*Source, _environmentFingerprint string, _context
return nil, _error
}

_libraryUrl := fmt.Sprintf ("unix:%s", path.Join (_context.cacheRoot, fmt.Sprintf ("%s-%08x.sock", generateRandomToken (), os.Getpid ())))
if _error := makeCacheFolder (_context.cacheRoot, "parse-sockets"); _error != nil {
return nil, _error
}
_libraryUrl := fmt.Sprintf ("unix:%s", path.Join (_context.cacheRoot, "parse-sockets", fmt.Sprintf ("%s-%08x.sock", generateRandomToken (), os.Getpid ())))

var _rpc *LibraryRpcServer
if _rpc_0, _error := NewLibraryRpcServer (_library, _libraryUrl); _error == nil {
Expand Down
5 changes: 4 additions & 1 deletion sources/lib/resolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ func resolveLibrary (_candidate string, _context *Context, _lookupPaths []string
var _cacheLibrary string

if _context.cacheEnabled && (_context.cacheRoot != "") {
_cacheLibrary = path.Join (_context.cacheRoot, _environmentFingerprint + ".cdb")
if _error := makeCacheFolder (_context.cacheRoot, "libraries-cdb"); _error != nil {
return nil, _error
}
_cacheLibrary = path.Join (_context.cacheRoot, "libraries-cdb", _environmentFingerprint + ".cdb")
if _, _error := os.Stat (_cacheLibrary); _error == nil {
if _library, _error := resolveLibraryCached (_cacheLibrary); _error == nil {
if _fresh, _error := checkLibraryCached (_library); _error == nil {
Expand Down
11 changes: 11 additions & 0 deletions sources/lib/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,14 @@ func replaceVariables (_input string) (string, *Error) {
return _input, nil
}




func makeCacheFolder (_cacheRoot string, _cacheFolder string) (*Error) {
_cache := path.Join (_cacheRoot, _cacheFolder)
if _error := os.MkdirAll (_cache, 0750); _error != nil {
return errorw (0x6f530744, _error)
}
return nil
}

5 changes: 4 additions & 1 deletion sources/lib/tools_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func createPipe (_size int, _cacheRoot string) (int, *os.File, *Error) {
// FIXME: We should make sure that the cache path is never empty!
panic (0xd6f17610)
}
_temporaryPath := path.Join (_cacheRoot, generateRandomToken () + ".buffer")
if _error := makeCacheFolder (_cacheRoot, "buffers"); _error != nil {
return -1, nil, _error
}
_temporaryPath := path.Join (_cacheRoot, "buffers", generateRandomToken () + ".buffer")
if _descriptor, _error := syscall.Open (_temporaryPath, syscall.O_CREAT | syscall.O_EXCL | syscall.O_WRONLY, 0600); _error == nil {
_interpreterScriptOutput = os.NewFile (uintptr (_descriptor), "")
} else {
Expand Down
5 changes: 4 additions & 1 deletion sources/lib/tools_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func createPipe (_size int, _cacheRoot string) (int, *os.File, *Error) {
// FIXME: We should make sure that the cache path is never empty!
panic (0xd6f17610)
}
_temporaryPath := path.Join (_cacheRoot, generateRandomToken () + ".buffer")
if _error := makeCacheFolder (_cacheRoot, "buffers"); _error != nil {
return -1, nil, _error
}
_temporaryPath := path.Join (_cacheRoot, "buffers", generateRandomToken () + ".buffer")
if _descriptor, _error := syscall.Open (_temporaryPath, syscall.O_CREAT | syscall.O_EXCL | syscall.O_WRONLY, 0600); _error == nil {
_interpreterScriptOutput = os.NewFile (uintptr (_descriptor), "")
} else {
Expand Down

0 comments on commit fd7b340

Please sign in to comment.