@@ -128,12 +128,10 @@ def walk_files(self, path_info, **kwargs):
128
128
yield PathInfo (f"{ root } { os .sep } { file } " )
129
129
130
130
def is_empty (self , path_info ):
131
- path = path_info .fspath
132
-
133
- if self .isfile (path_info ) and os .path .getsize (path ) == 0 :
131
+ if self .isfile (path_info ) and os .path .getsize (path_info ) == 0 :
134
132
return True
135
133
136
- if self .isdir (path_info ) and len (os .listdir (path )) == 0 :
134
+ if self .isdir (path_info ) and len (os .listdir (path_info )) == 0 :
137
135
return True
138
136
139
137
return False
@@ -142,12 +140,7 @@ def remove(self, path_info):
142
140
if isinstance (path_info , PathInfo ):
143
141
if path_info .scheme != "local" :
144
142
raise NotImplementedError
145
- path = path_info .fspath
146
- else :
147
- path = path_info
148
-
149
- if self .exists (path ):
150
- remove (path )
143
+ remove (path_info )
151
144
152
145
def makedirs (self , path_info ):
153
146
makedirs (path_info , exist_ok = True , mode = self .dir_mode )
@@ -226,11 +219,7 @@ def hardlink(self, from_info, to_info):
226
219
if self .getsize (from_info ) == 0 :
227
220
self .open (to_info , "w" ).close ()
228
221
229
- logger .debug (
230
- "Created empty file: {src} -> {dest}" .format (
231
- src = str (from_info ), dest = str (to_info )
232
- )
233
- )
222
+ logger .debug ("Created empty file: %s -> %s" , from_info , to_info )
234
223
return
235
224
236
225
System .hardlink (from_info , to_info )
@@ -248,9 +237,8 @@ def reflink(self, from_info, to_info):
248
237
os .rename (tmp_info , to_info )
249
238
250
239
def chmod (self , path_info , mode ):
251
- path = os .fspath (path_info )
252
240
try :
253
- os .chmod (path , mode )
241
+ os .chmod (path_info , mode )
254
242
except OSError as exc :
255
243
# There is nothing we need to do in case of a read-only file system
256
244
if exc .errno == errno .EROFS :
@@ -261,13 +249,13 @@ def chmod(self, path_info, mode):
261
249
if exc .errno not in [errno .EPERM , errno .EACCES ]:
262
250
raise
263
251
264
- actual = stat .S_IMODE (os .stat (path ).st_mode )
252
+ actual = stat .S_IMODE (os .stat (path_info ).st_mode )
265
253
if actual != mode :
266
254
raise
267
255
268
256
def _unprotect_file (self , path ):
269
257
if System .is_symlink (path ) or System .is_hardlink (path ):
270
- logger .debug (f "Unprotecting '{ path } '" )
258
+ logger .debug ("Unprotecting '%s'" , path )
271
259
tmp = os .path .join (os .path .dirname (path ), "." + uuid ())
272
260
273
261
# The operations order is important here - if some application
@@ -281,8 +269,9 @@ def _unprotect_file(self, path):
281
269
282
270
else :
283
271
logger .debug (
284
- "Skipping copying for '{}', since it is not "
285
- "a symlink or a hardlink." .format (path )
272
+ "Skipping copying for '%s', since it is not "
273
+ "a symlink or a hardlink." ,
274
+ path ,
286
275
)
287
276
288
277
os .chmod (path , self .file_mode )
@@ -292,14 +281,15 @@ def _unprotect_dir(self, path):
292
281
self ._unprotect_file (fname )
293
282
294
283
def unprotect (self , path_info ):
295
- path = path_info .fspath
296
- if not os .path .exists (path ):
297
- raise DvcException (f"can't unprotect non-existing data '{ path } '" )
284
+ if not os .path .exists (path_info ):
285
+ raise DvcException (
286
+ f"can't unprotect non-existing data '{ path_info } '"
287
+ )
298
288
299
- if os .path .isdir (path ):
300
- self ._unprotect_dir (path )
289
+ if os .path .isdir (path_info ):
290
+ self ._unprotect_dir (path_info )
301
291
else :
302
- self ._unprotect_file (path )
292
+ self ._unprotect_file (path_info )
303
293
304
294
def protect (self , path_info ):
305
295
self .chmod (path_info , self .CACHE_MODE )
0 commit comments