MCPcopy Index your code
hub / github.com/RustPython/RustPython / touch

Method touch

Lib/pathlib/__init__.py:984–1004  ·  view source on GitHub ↗

Create this file with the given access mode, if it doesn't exist.

(self, mode=0o666, exist_ok=True)

Source from the content-addressed store, hash-verified

982 raise UnsupportedOperation(f"{f} is unsupported on this system")
983
984 def touch(self, mode=0o666, exist_ok=True):
985 """
986 Create this file with the given access mode, if it doesn't exist.
987 """
988
989 if exist_ok:
990 # First try to bump modification time
991 # Implementation note: GNU touch uses the UTIME_NOW option of
992 # the utimensat() / futimens() functions.
993 try:
994 os.utime(self, None)
995 except OSError:
996 # Avoid exception chaining
997 pass
998 else:
999 return
1000 flags = os.O_CREAT | os.O_WRONLY
1001 if not exist_ok:
1002 flags |= os.O_EXCL
1003 fd = os.open(self, flags, mode)
1004 os.close(fd)
1005
1006 def mkdir(self, mode=0o777, parents=False, exist_ok=False):
1007 """

Callers 1

__init__Method · 0.45

Calls 3

utimeMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected