mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-22 11:25:08 +00:00
Implements multiple temp folders for Linux/macOS.
This commit is contained in:
parent
b1425334b8
commit
4a950c7c94
1 changed files with 60 additions and 11 deletions
|
@ -221,19 +221,68 @@ DIM SHARED tmpdir AS STRING, tmpdir2 AS STRING
|
||||||
IF os$ = "WIN" THEN tmpdir$ = ".\internal\temp\": tmpdir2$ = "..\\temp\\"
|
IF os$ = "WIN" THEN tmpdir$ = ".\internal\temp\": tmpdir2$ = "..\\temp\\"
|
||||||
IF os$ = "LNX" THEN tmpdir$ = "./internal/temp/": tmpdir2$ = "../temp/"
|
IF os$ = "LNX" THEN tmpdir$ = "./internal/temp/": tmpdir2$ = "../temp/"
|
||||||
|
|
||||||
|
DECLARE LIBRARY
|
||||||
|
FUNCTION getpid& ()
|
||||||
|
END DECLARE
|
||||||
|
|
||||||
|
thisinstancepid = getpid&
|
||||||
DIM SHARED tempfolderindex
|
DIM SHARED tempfolderindex
|
||||||
E = 0
|
|
||||||
i = 1
|
IF INSTR(_OS$, "LINUX") THEN
|
||||||
OPEN tmpdir$ + "temp.bin" FOR OUTPUT LOCK WRITE AS #26
|
fh = FREEFILE
|
||||||
DO WHILE E
|
OPEN ".\internal\temp\tempfoldersearch.bin" FOR RANDOM AS #fh LEN = LEN(tempfolderindex)
|
||||||
i = i + 1
|
tempfolderrecords = LOF(fh) / LEN(tempfolderindex)
|
||||||
IF i = 1000 THEN PRINT "Unable to locate the 'internal' folder": END
|
i = 1
|
||||||
MKDIR ".\internal\temp" + str2$(i)
|
IF tempfolderrecords = 0 THEN
|
||||||
IF os$ = "WIN" THEN tmpdir$ = ".\internal\temp" + str2$(i) + "\": tmpdir2$ = "..\\temp" + str2$(i) + "\\"
|
'first run ever?
|
||||||
IF os$ = "LNX" THEN tmpdir$ = "./internal/temp" + str2$(i) + "/": tmpdir2$ = "../temp" + str2$(i) + "/"
|
PUT #fh, 1, thisinstancepid
|
||||||
E = 0
|
ELSE
|
||||||
|
FOR i = 1 TO tempfolderrecords
|
||||||
|
'check if any of the temp folders is being used = pid still active
|
||||||
|
GET #fh, i, tempfoldersearch
|
||||||
|
|
||||||
|
SHELL _HIDE "ps -p " + STR$(tempfoldersearch) + " > /dev/null 2>&1; echo $? > internal/temp/checkpid.bin"
|
||||||
|
fh2 = FREEFILE
|
||||||
|
OPEN "internal/temp/checkpid.bin" FOR BINARY AS #fh2
|
||||||
|
LINE INPUT #fh2, checkpid$
|
||||||
|
CLOSE #fh2
|
||||||
|
IF VAL(checkpid$) = 1 THEN
|
||||||
|
'This temp folder was locked by an instance that's no longer active, so
|
||||||
|
'this will be our temp folder
|
||||||
|
PUT #fh, i, thisinstancepid
|
||||||
|
EXIT FOR
|
||||||
|
END IF
|
||||||
|
NEXT
|
||||||
|
IF i > tempfolderrecords THEN
|
||||||
|
'All indexes were busy. Let's initiate a new one:
|
||||||
|
PUT #fh, i, thisinstancepid
|
||||||
|
END IF
|
||||||
|
END IF
|
||||||
|
CLOSE #fh
|
||||||
|
IF i > 1 THEN
|
||||||
|
tmpdir$ = "./internal/temp" + str2$(i) + "/": tmpdir2$ = "../temp" + str2$(i) + "/"
|
||||||
|
IF _DIREXISTS(tmpdir$) = 0 THEN
|
||||||
|
MKDIR tmpdir$
|
||||||
|
END IF
|
||||||
|
END IF
|
||||||
OPEN tmpdir$ + "temp.bin" FOR OUTPUT LOCK WRITE AS #26
|
OPEN tmpdir$ + "temp.bin" FOR OUTPUT LOCK WRITE AS #26
|
||||||
LOOP
|
ELSE
|
||||||
|
ON ERROR GOTO qberror_test
|
||||||
|
E = 0
|
||||||
|
i = 1
|
||||||
|
OPEN tmpdir$ + "temp.bin" FOR OUTPUT LOCK WRITE AS #26
|
||||||
|
DO WHILE E
|
||||||
|
i = i + 1
|
||||||
|
IF i = 1000 THEN PRINT "Unable to locate the 'internal' folder": END
|
||||||
|
MKDIR ".\internal\temp" + str2$(i)
|
||||||
|
IF os$ = "WIN" THEN tmpdir$ = ".\internal\temp" + str2$(i) + "\": tmpdir2$ = "..\\temp" + str2$(i) + "\\"
|
||||||
|
IF os$ = "LNX" THEN tmpdir$ = "./internal/temp" + str2$(i) + "/": tmpdir2$ = "../temp" + str2$(i) + "/"
|
||||||
|
E = 0
|
||||||
|
OPEN tmpdir$ + "temp.bin" FOR OUTPUT LOCK WRITE AS #26
|
||||||
|
LOOP
|
||||||
|
END IF
|
||||||
|
|
||||||
|
|
||||||
'temp folder established
|
'temp folder established
|
||||||
tempfolderindex = i
|
tempfolderindex = i
|
||||||
IF i > 1 THEN
|
IF i > 1 THEN
|
||||||
|
|
Loading…
Reference in a new issue