@@ -111,8 +111,8 @@ def _ls(self, path):
111
111
""" List files at given path """
112
112
path = AzureDLPath (path ).trim ()
113
113
key = path .as_posix ()
114
- if path not in self .dirs :
115
- out = self .azure .call ('LISTSTATUS' , path . as_posix () )
114
+ if key not in self .dirs :
115
+ out = self .azure .call ('LISTSTATUS' , key )
116
116
self .dirs [key ] = out ['FileStatuses' ]['FileStatus' ]
117
117
for f in self .dirs [key ]:
118
118
f ['name' ] = (path / f ['pathSuffix' ]).as_posix ()
@@ -137,10 +137,12 @@ def info(self, path):
137
137
"""
138
138
path = AzureDLPath (path ).trim ()
139
139
root = path .parent
140
- myfile = [f for f in self ._ls (root ) if f ['name' ] == path .as_posix ()]
141
- if len (myfile ) == 1 :
142
- return myfile [0 ]
143
- raise FileNotFoundError (path )
140
+ path_as_posix = path .as_posix ()
141
+ for f in self ._ls (root ):
142
+ if f ['name' ] == path_as_posix :
143
+ return f
144
+ else :
145
+ raise FileNotFoundError (path )
144
146
145
147
def _walk (self , path ):
146
148
fi = list (self ._ls (path ))
@@ -149,21 +151,22 @@ def _walk(self, path):
149
151
fi .extend (self ._ls (apath ['name' ]))
150
152
return [f for f in fi if f ['type' ] == 'FILE' ]
151
153
152
- def walk (self , path = '' ):
154
+ def walk (self , path = '' , details = False ):
153
155
""" Get all files below given path
154
156
"""
155
- return [f ['name' ] for f in self ._walk (path )]
157
+ return [f if details else f ['name' ] for f in self ._walk (path )]
156
158
157
- def glob (self , path ):
159
+ def glob (self , path , details = False ):
158
160
"""
159
161
Find files (not directories) by glob-matching.
160
162
"""
161
163
path = AzureDLPath (path ).trim ()
164
+ path_as_posix = path .as_posix ()
162
165
prefix = path .globless_prefix
163
- allfiles = self .walk (prefix )
166
+ allfiles = self .walk (prefix , details )
164
167
if prefix == path :
165
168
return allfiles
166
- return [f for f in allfiles if AzureDLPath (f ).match (path . as_posix () )]
169
+ return [f for f in allfiles if AzureDLPath (f [ 'name' ] if details else f ).match (path_as_posix )]
167
170
168
171
def du (self , path , total = False , deep = False ):
169
172
""" Bytes in keys at path """
@@ -233,8 +236,9 @@ def set_expiry(self, path, expiry_option, expire_time=None):
233
236
parms ['expireTime' ] = int (expire_time )
234
237
235
238
self .azure .call ('SETEXPIRY' , path .as_posix (), is_extended = True , ** parms )
239
+ self .invalidate_cache (path .as_posix ())
236
240
237
- def _acl_call (self , action , path , acl_spec = None ):
241
+ def _acl_call (self , action , path , acl_spec = None , invalidate_cache = False ):
238
242
"""
239
243
Helper method for ACL calls to reduce code repetition
240
244
@@ -249,13 +253,21 @@ def _acl_call(self, action, path, acl_spec=None):
249
253
'[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,...'
250
254
251
255
Note that for remove acl entries the permission (rwx) portion is not required.
256
+ invalidate_cache: bool
257
+ optionally indicates that the cache of files should be invalidated after this operation
258
+ This should always be done for set and remove operations, since the state of the file or folder has changed.
252
259
"""
253
260
parms = {}
254
261
path = AzureDLPath (path ).trim ()
262
+ posix_path = path .as_posix ()
255
263
if acl_spec :
256
264
parms ['aclSpec' ] = acl_spec
257
265
258
- return self .azure .call (action , path .as_posix (), ** parms )
266
+ to_return = self .azure .call (action , posix_path , ** parms )
267
+ if invalidate_cache :
268
+ self .invalidate_cache (posix_path )
269
+
270
+ return to_return
259
271
260
272
def set_acl (self , path , acl_spec ):
261
273
"""
@@ -272,7 +284,8 @@ def set_acl(self, path, acl_spec):
272
284
'[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,...'
273
285
"""
274
286
275
- self ._acl_call ('SETACL' , path , acl_spec )
287
+ self ._acl_call ('SETACL' , path , acl_spec , invalidate_cache = True )
288
+
276
289
277
290
def modify_acl_entries (self , path , acl_spec ):
278
291
"""
@@ -290,7 +303,8 @@ def modify_acl_entries(self, path, acl_spec):
290
303
The ACL specification to use in modifying the ACL at the path in the format
291
304
'[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,[default:]user|group|other:[entity id or UPN]:r|-w|-x|-,...'
292
305
"""
293
- self ._acl_call ('MODIFYACLENTRIES' , path , acl_spec )
306
+ self ._acl_call ('MODIFYACLENTRIES' , path , acl_spec , invalidate_cache = True )
307
+
294
308
295
309
def remove_acl_entries (self , path , acl_spec ):
296
310
"""
@@ -309,7 +323,8 @@ def remove_acl_entries(self, path, acl_spec):
309
323
The ACL specification to remove from the ACL at the path in the format (note that the permission portion is missing)
310
324
'[default:]user|group|other:[entity id or UPN],[default:]user|group|other:[entity id or UPN],...'
311
325
"""
312
- self ._acl_call ('REMOVEACLENTRIES' , path , acl_spec )
326
+ self ._acl_call ('REMOVEACLENTRIES' , path , acl_spec , invalidate_cache = True )
327
+
313
328
314
329
def get_acl_status (self , path ):
315
330
"""
@@ -334,7 +349,8 @@ def remove_acl(self, path):
334
349
path: str
335
350
Location to remove the ACL.
336
351
"""
337
- self ._acl_call ('REMOVEACL' , path )
352
+ self ._acl_call ('REMOVEACL' , path , invalidate_cache = True )
353
+
338
354
339
355
def remove_default_acl (self , path ):
340
356
"""
@@ -349,7 +365,8 @@ def remove_default_acl(self, path):
349
365
path: str
350
366
Location to set the ACL on.
351
367
"""
352
- self ._acl_call ('REMOVEDEFAULTACL' , path )
368
+ self ._acl_call ('REMOVEDEFAULTACL' , path , invalidate_cache = True )
369
+
353
370
354
371
def chown (self , path , owner = None , group = None ):
355
372
"""
@@ -375,6 +392,7 @@ def chown(self, path, owner=None, group=None):
375
392
parms ['group' ] = group
376
393
path = AzureDLPath (path ).trim ()
377
394
self .azure .call ('SETOWNER' , path .as_posix (), ** parms )
395
+ self .invalidate_cache (path .as_posix ())
378
396
379
397
def exists (self , path ):
380
398
""" Does such a file/directory exist? """
0 commit comments