@@ -431,7 +431,23 @@ def link(self, src, dst):
431
431
def symlink (self , src , dst , target_is_directory = False ):
432
432
raise NotImplementedError ("os.symlink() not available on this system" )
433
433
434
- utime = os .utime
434
+ def touch (self , path , mode = 0o666 , exist_ok = True ):
435
+ if exist_ok :
436
+ # First try to bump modification time
437
+ # Implementation note: GNU touch uses the UTIME_NOW option of
438
+ # the utimensat() / futimens() functions.
439
+ try :
440
+ os .utime (path , None )
441
+ except OSError :
442
+ # Avoid exception chaining
443
+ pass
444
+ else :
445
+ return
446
+ flags = os .O_CREAT | os .O_WRONLY
447
+ if not exist_ok :
448
+ flags |= os .O_EXCL
449
+ fd = os .open (path , flags , mode )
450
+ os .close (fd )
435
451
436
452
if hasattr (os , "readlink" ):
437
453
readlink = os .readlink
@@ -1100,13 +1116,6 @@ def _opener(self, name, flags, mode=0o666):
1100
1116
# A stub for the opener argument to built-in open()
1101
1117
return self ._accessor .open (self , flags , mode )
1102
1118
1103
- def _raw_open (self , flags , mode = 0o777 ):
1104
- """
1105
- Open the file pointed by this path and return a file descriptor,
1106
- as os.open() does.
1107
- """
1108
- return self ._accessor .open (self , flags , mode )
1109
-
1110
1119
# Public API
1111
1120
1112
1121
@classmethod
@@ -1283,22 +1292,7 @@ def touch(self, mode=0o666, exist_ok=True):
1283
1292
"""
1284
1293
Create this file with the given access mode, if it doesn't exist.
1285
1294
"""
1286
- if exist_ok :
1287
- # First try to bump modification time
1288
- # Implementation note: GNU touch uses the UTIME_NOW option of
1289
- # the utimensat() / futimens() functions.
1290
- try :
1291
- self ._accessor .utime (self , None )
1292
- except OSError :
1293
- # Avoid exception chaining
1294
- pass
1295
- else :
1296
- return
1297
- flags = os .O_CREAT | os .O_WRONLY
1298
- if not exist_ok :
1299
- flags |= os .O_EXCL
1300
- fd = self ._raw_open (flags , mode )
1301
- os .close (fd )
1295
+ self ._accessor .touch (self , mode , exist_ok )
1302
1296
1303
1297
def mkdir (self , mode = 0o777 , parents = False , exist_ok = False ):
1304
1298
"""
0 commit comments