-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.py
More file actions
60 lines (49 loc) · 1.96 KB
/
lock.py
File metadata and controls
60 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# module lock
import os
from pathlib import Path
import time
import fnmatch
def searchLock(challenge_name):
folder = os.environ['SECUREMIRROR_CAPTURES']
while os.path.isdir(folder)==False:
print(" challenge : SECUREMIRROR_CAPTURES environment variable not valid")
return False
time.sleep(60) # check and sleep forever
# Si llegamos aqui, el directorio existe
for file in os.listdir(folder):
if fnmatch.fnmatch(file,'lock_*'):
print("file found:", file)
# Hemos encontrado un fichero que cumple
# Si es nuestro challenge, ignoramos
# if file=="lock_" + challenge_name:
# print("El lock es de este mismo challenge: lo ignoramos")
# continue
creation_date = os.path.getctime(folder + "/" + file)
now = time.time()
if (now > creation_date+300): # 5 minutos es viejo
# Es viejo
print(file, "is old")
continue
else:
return False
return True
def lockIN(challenge_name):
# Mientras exista un fichero lock* se queda en bucle
while True:
search = searchLock(challenge_name)
if (search==True):
break
else:
time.sleep(5)
# Si llegamos aquies que no hay lock o lo que hay es viejo
# Tambien tenemos garantizado si llegamos aqui que folder existe
folder = os.environ['SECUREMIRROR_CAPTURES']
# Borramos un posible fichero viejo nuestro
if os.path.exists(folder + "/" + "lock_" + challenge_name):
os.remove(folder + "/" + "lock_" + challenge_name)
# Creamos el nuevo
Path(folder + "/" + "lock_" + challenge_name).touch()
def lockOUT(challenge_name):
folder = os.environ['SECUREMIRROR_CAPTURES']
if os.path.exists(folder + "/" + "lock_" + challenge_name):
os.remove(folder + "/" + "lock_" + challenge_name)