@@ -444,7 +444,23 @@ def symlink(a, b, target_is_directory):
444
444
def symlink (a , b , target_is_directory ):
445
445
return os .symlink (a , b )
446
446
447
- utime = os .utime
447
+ def touch (self , path , mode = 0o666 , exist_ok = True ):
448
+ if exist_ok :
449
+ # First try to bump modification time
450
+ # Implementation note: GNU touch uses the UTIME_NOW option of
451
+ # the utimensat() / futimens() functions.
452
+ try :
453
+ os .utime (path , None )
454
+ except OSError :
455
+ # Avoid exception chaining
456
+ pass
457
+ else :
458
+ return
459
+ flags = os .O_CREAT | os .O_WRONLY
460
+ if not exist_ok :
461
+ flags |= os .O_EXCL
462
+ fd = os .open (path , flags , mode )
463
+ os .close (fd )
448
464
449
465
# Helper for resolve()
450
466
def readlink (self , path ):
@@ -1111,13 +1127,6 @@ def _opener(self, name, flags, mode=0o666):
1111
1127
# A stub for the opener argument to built-in open()
1112
1128
return self ._accessor .open (self , flags , mode )
1113
1129
1114
- def _raw_open (self , flags , mode = 0o777 ):
1115
- """
1116
- Open the file pointed by this path and return a file descriptor,
1117
- as os.open() does.
1118
- """
1119
- return self ._accessor .open (self , flags , mode )
1120
-
1121
1130
# Public API
1122
1131
1123
1132
@classmethod
@@ -1290,22 +1299,7 @@ def touch(self, mode=0o666, exist_ok=True):
1290
1299
"""
1291
1300
Create this file with the given access mode, if it doesn't exist.
1292
1301
"""
1293
- if exist_ok :
1294
- # First try to bump modification time
1295
- # Implementation note: GNU touch uses the UTIME_NOW option of
1296
- # the utimensat() / futimens() functions.
1297
- try :
1298
- self ._accessor .utime (self , None )
1299
- except OSError :
1300
- # Avoid exception chaining
1301
- pass
1302
- else :
1303
- return
1304
- flags = os .O_CREAT | os .O_WRONLY
1305
- if not exist_ok :
1306
- flags |= os .O_EXCL
1307
- fd = self ._raw_open (flags , mode )
1308
- os .close (fd )
1302
+ self ._accessor .touch (self , mode , exist_ok )
1309
1303
1310
1304
def mkdir (self , mode = 0o777 , parents = False , exist_ok = False ):
1311
1305
"""
0 commit comments