1
1
import logging
2
2
import os
3
3
import time
4
+ from urllib .parse import quote_plus
4
5
5
6
from filelock import FileLock
6
7
@@ -23,7 +24,7 @@ class AbstractFileSystem(Storage):
23
24
Not directories in directories.
24
25
"""
25
26
26
- def __init__ (self , conf_dict ):
27
+ def __init__ (self , conf_dict , ):
27
28
"""
28
29
items = FileSystem(
29
30
{
@@ -44,15 +45,12 @@ def __init__(self, conf_dict):
44
45
45
46
super ().__init__ (conf_dict )
46
47
self .config = conf_dict
47
- _fdir = conf_dict .get ('fdir' , '' )
48
- if '{issuer}' in _fdir :
49
- issuer = conf_dict .get ('issuer' )
50
- if not issuer :
51
- raise ValueError ('Missing issuer value' )
52
- self .fdir = _fdir .format (issuer = issuer )
53
- else :
54
- self .fdir = _fdir
55
48
49
+ _fdir = conf_dict .get ('fdir' , '.' )
50
+ if "issuer" in conf_dict :
51
+ _fdir = os .path .join (_fdir , quote_plus (conf_dict ["issuer" ]))
52
+
53
+ self .fdir = _fdir
56
54
self .fmtime = {}
57
55
self .storage = {}
58
56
@@ -87,11 +85,13 @@ def __getitem__(self, item):
87
85
:return:
88
86
"""
89
87
item = self .key_conv .serialize (item )
90
- if self ._is_file (item ):
91
- if self .is_changed (item ):
92
- logger .info ("File content change in {}" .format (item ))
93
- fname = os .path .join (self .fdir , item )
94
- self .storage [item ] = self ._read_info (fname )
88
+ fname = os .path .join (self .fdir , item )
89
+ if self ._is_file (fname ):
90
+ lock = FileLock ('{}.lock' .format (fname ))
91
+ with lock :
92
+ if self .is_changed (item , fname ):
93
+ logger .info ("File content change in {}" .format (item ))
94
+ self .storage [item ] = self ._read_info (fname )
95
95
96
96
logger .debug ('Read from "%s"' , item )
97
97
return self .storage [item ]
@@ -165,19 +165,17 @@ def get_mtime(fname):
165
165
166
166
return mtime
167
167
168
- def _is_file (self , item ):
169
- fname = os .path .join (self .fdir , item )
168
+ def _is_file (self , fname ):
170
169
return os .path .isfile (fname )
171
170
172
- def is_changed (self , item ):
171
+ def is_changed (self , item , fname ):
173
172
"""
174
173
Find out if this item has been modified since last.
175
174
When I get here I know that item points to an existing file.
176
175
177
176
:param item: A key
178
177
:return: True/False
179
178
"""
180
- fname = os .path .join (self .fdir , item )
181
179
mtime = self .get_mtime (fname )
182
180
183
181
try :
@@ -223,7 +221,7 @@ def synch(self):
223
221
continue
224
222
225
223
if f in self .fmtime :
226
- if self .is_changed (f ):
224
+ if self .is_changed (f , fname ):
227
225
self .storage [f ] = self ._read_info (fname )
228
226
else :
229
227
mtime = self .get_mtime (fname )
0 commit comments