Skip to content

Commit fd7b340

Browse files
[cache] Create various cache files in subfolders. [see issue #30]
1 parent 6dada14 commit fd7b340

File tree

8 files changed

+49
-13
lines changed

8 files changed

+49
-13
lines changed

sources/lib/commands.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ func doHandleExecuteScriptletSsh (_library LibraryStore, _scriptlet *Scriptlet,
281281
_sshCache = "/tmp"
282282
}
283283

284+
if _error := makeCacheFolder (_context.cacheRoot, "ssh-sockets"); _error != nil {
285+
return false, _error
286+
}
284287
if _sshLibraryLocalSocket == "" {
285-
_sshLibraryLocalSocket = path.Join (_context.cacheRoot, fmt.Sprintf ("%s-%08x.sock", _sshToken, os.Getpid ()))
288+
_sshLibraryLocalSocket = path.Join (_context.cacheRoot, "ssh-sockets", fmt.Sprintf ("%s-%08x.sock", _sshToken, os.Getpid ()))
286289
}
287290
if _sshLibraryRemoteSocket == "" {
288291
_sshLibraryRemoteSocket = path.Join (_sshCache, fmt.Sprintf ("z-run--%s.sock", _sshToken))
@@ -308,7 +311,7 @@ func doHandleExecuteScriptletSsh (_library LibraryStore, _scriptlet *Scriptlet,
308311
ExecutablePaths : _invokeExecutablePaths,
309312
Terminal : _sshTerminal,
310313
Workspace : _sshWorkspace,
311-
Cache : _sshCache,
314+
CacheRoot : _sshCache,
312315
}
313316

314317
var _invokeContextEncoded string

sources/lib/execution.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,19 @@ func prepareExecution_0 (
388388

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

391+
if _error := makeCacheFolder (_contextCacheRoot, "go-root"); _error != nil {
392+
return nil, nil, _error
393+
}
394+
if _error := makeCacheFolder (_contextCacheRoot, "go-sources"); _error != nil {
395+
return nil, nil, _error
396+
}
397+
if _error := makeCacheFolder (_contextCacheRoot, "go-executables"); _error != nil {
398+
return nil, nil, _error
399+
}
400+
391401
_goFingerprint := _scriptletFingerprint
392-
_goSource := path.Join (_contextCacheRoot, _goFingerprint + ".go")
393-
_goExecutable := path.Join (_contextCacheRoot, _goFingerprint + ".exec")
402+
_goSource := path.Join (_contextCacheRoot, "go-sources", _goFingerprint + ".go")
403+
_goExecutable := path.Join (_contextCacheRoot, "go-executables", _goFingerprint + ".exec")
394404

395405
if _, _error := os.Stat (_goExecutable); _error == nil {
396406
// PASS
@@ -419,17 +429,17 @@ func prepareExecution_0 (
419429
_interpreterScriptBuffer.WriteString (_scriptletBody)
420430
}
421431

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

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

432-
_goRoot := path.Join (_contextCacheRoot, "go")
442+
_goRoot := path.Join (_contextCacheRoot, "go-root")
433443
_goCache := path.Join (_goRoot, "cache")
434444
_goTmp := path.Join (_goRoot, "tmp")
435445
for _, _mkdirPath := range []string { _goRoot, _goCache, _goTmp } {

sources/lib/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type InvokeContext struct {
5353
ExecutablePaths []string `json:"executable-paths,omitempty"`
5454
Terminal string `json:"terminal,omitempty"`
5555
Workspace string `json:"workspace,omitempty"`
56-
Cache string `json:"cache,omitempty"`
56+
CacheRoot string `json:"cache-root,omitempty"`
5757
}
5858

5959

@@ -409,7 +409,7 @@ func Main (_executable string, _argument0 string, _arguments []string, _environm
409409
_terminal = _context.Terminal
410410
_libraryCacheUrl = _context.Library
411411
_workspace = _context.Workspace
412-
_cacheRoot = _context.Cache
412+
_cacheRoot = _context.CacheRoot
413413
_top = false
414414
}
415415

sources/lib/parser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ func parseLibrary (_sources []*Source, _environmentFingerprint string, _context
4949
return nil, _error
5050
}
5151

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

5457
var _rpc *LibraryRpcServer
5558
if _rpc_0, _error := NewLibraryRpcServer (_library, _libraryUrl); _error == nil {

sources/lib/resolution.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ func resolveLibrary (_candidate string, _context *Context, _lookupPaths []string
240240
var _cacheLibrary string
241241

242242
if _context.cacheEnabled && (_context.cacheRoot != "") {
243-
_cacheLibrary = path.Join (_context.cacheRoot, _environmentFingerprint + ".cdb")
243+
if _error := makeCacheFolder (_context.cacheRoot, "libraries-cdb"); _error != nil {
244+
return nil, _error
245+
}
246+
_cacheLibrary = path.Join (_context.cacheRoot, "libraries-cdb", _environmentFingerprint + ".cdb")
244247
if _, _error := os.Stat (_cacheLibrary); _error == nil {
245248
if _library, _error := resolveLibraryCached (_cacheLibrary); _error == nil {
246249
if _fresh, _error := checkLibraryCached (_library); _error == nil {

sources/lib/tools.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,14 @@ func replaceVariables (_input string) (string, *Error) {
152152
return _input, nil
153153
}
154154

155+
156+
157+
158+
func makeCacheFolder (_cacheRoot string, _cacheFolder string) (*Error) {
159+
_cache := path.Join (_cacheRoot, _cacheFolder)
160+
if _error := os.MkdirAll (_cache, 0750); _error != nil {
161+
return errorw (0x6f530744, _error)
162+
}
163+
return nil
164+
}
165+

sources/lib/tools_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ func createPipe (_size int, _cacheRoot string) (int, *os.File, *Error) {
4141
// FIXME: We should make sure that the cache path is never empty!
4242
panic (0xd6f17610)
4343
}
44-
_temporaryPath := path.Join (_cacheRoot, generateRandomToken () + ".buffer")
44+
if _error := makeCacheFolder (_cacheRoot, "buffers"); _error != nil {
45+
return -1, nil, _error
46+
}
47+
_temporaryPath := path.Join (_cacheRoot, "buffers", generateRandomToken () + ".buffer")
4548
if _descriptor, _error := syscall.Open (_temporaryPath, syscall.O_CREAT | syscall.O_EXCL | syscall.O_WRONLY, 0600); _error == nil {
4649
_interpreterScriptOutput = os.NewFile (uintptr (_descriptor), "")
4750
} else {

sources/lib/tools_others.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func createPipe (_size int, _cacheRoot string) (int, *os.File, *Error) {
4646
// FIXME: We should make sure that the cache path is never empty!
4747
panic (0xd6f17610)
4848
}
49-
_temporaryPath := path.Join (_cacheRoot, generateRandomToken () + ".buffer")
49+
if _error := makeCacheFolder (_cacheRoot, "buffers"); _error != nil {
50+
return -1, nil, _error
51+
}
52+
_temporaryPath := path.Join (_cacheRoot, "buffers", generateRandomToken () + ".buffer")
5053
if _descriptor, _error := syscall.Open (_temporaryPath, syscall.O_CREAT | syscall.O_EXCL | syscall.O_WRONLY, 0600); _error == nil {
5154
_interpreterScriptOutput = os.NewFile (uintptr (_descriptor), "")
5255
} else {

0 commit comments

Comments
 (0)