Skip to content

Commit cd73136

Browse files
authored
#730 - fix race condition by invoking find only once (#731)
1 parent 274e948 commit cd73136

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

code/processes/housekeeping.q

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ csvloader:{[CSV]
5555
//-Sees if the function in the CSV file is in the function list. if so- it carries out that function on files that match the parameters in the csv [using find function]
5656
wrapper:{[DICT]
5757
if[not DICT[`function] in key `.;:.lg.e[`housekeeping;"Could not find function: ",string DICT`function]];
58-
p:find[.rmvr.removeenvvar DICT`path;;DICT`age;DICT`agemin;DICT`checkfordirectory];
59-
value[DICT`function] each p[DICT`match] except p DICT`exclude}
58+
value[DICT`function] each find[.rmvr.removeenvvar DICT`path;DICT`match;DICT`exclude;DICT`age;DICT`agemin;DICT`checkfordirectory]}
6059

6160

6261

@@ -73,17 +72,16 @@ kdbzip:{[FILE]
7372
\d .unix
7473

7574
//-locates files or directories with path, matching string and age
76-
find:{[path;match;age;agemin;checkfordirectory]
75+
find:{[path;match;exclude;age;agemin;checkfordirectory]
7776
$[0=checkfordirectory;[fileordir:"files";flag:"f"];[fileordir:"directories";flag:"d"]];
7877
dayormin:$[0=agemin;"mtime";"mmin"];
79-
findmatches:{[path;match;age;fileordir;flag;dayormin]
78+
findmatches:{[path;match;exclude;age;fileordir;flag;dayormin]
8079
.lg.o[`housekeeping;"Searching for ",fileordir,": ",path,match];
81-
.proc.sys "/usr/bin/find ",path," -maxdepth 1 -type ",flag," -name \"",match,"\" -",dayormin," +",raze string age};
82-
matches:.[findmatches;(path;match;age;fileordir;flag;dayormin);{.lg.e[`housekeeping;"Find function failed: ",x];()}];
80+
.proc.sys "/usr/bin/find ",path," -maxdepth 1 -type ",flag," -name \"",match,"\" -",dayormin," +",(raze string age)," ! -name \"",exclude,"\""};
81+
matches:.[findmatches;(path;match;exclude;age;fileordir;flag;dayormin);{.lg.e[`housekeeping;"Find function failed: ",x];()}];
8382
if[0=count matches;.lg.o[`housekeeping;"No matching ",fileordir," located"]];
8483
matches}
8584

86-
8785
//-removes files
8886
rm:{[FILE]
8987
@[{.lg.o[`housekeeping;"removing ",x]; .proc.sys "/bin/rm -f ",x};FILE; {.lg.e[`housekeeping;"Failed to remove ",x," : ", y]}[FILE]]}

0 commit comments

Comments
 (0)