MCPcopy Create free account
hub / github.com/python/cpython / _fs_supports_holes

Method _fs_supports_holes

Lib/test/test_tarfile.py:1294–1313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1292
1293 @staticmethod
1294 def _fs_supports_holes():
1295 # Return True if the platform knows the st_blocks stat attribute and
1296 # uses st_blocks units of 512 bytes, and if the filesystem is able to
1297 # store holes of 4 KiB in files.
1298 #
1299 # The function returns False if page size is larger than 4 KiB.
1300 # For example, ppc64 uses pages of 64 KiB.
1301 if sys.platform.startswith(("linux", "android")):
1302 # Linux evidentially has 512 byte st_blocks units.
1303 name = os.path.join(TEMPDIR, "sparse-test")
1304 with open(name, "wb") as fobj:
1305 # Seek to "punch a hole" of 4 KiB
1306 fobj.seek(4096)
1307 fobj.write(b'x' * 4096)
1308 fobj.truncate()
1309 s = os.stat(name)
1310 os_helper.unlink(name)
1311 return (s.st_blocks * 512 < s.st_size)
1312 else:
1313 return False
1314
1315
1316class PaxReadTest(LongnameTest, ReadTest, unittest.TestCase):

Callers 1

_test_sparse_fileMethod · 0.95

Calls 8

openFunction · 0.50
startswithMethod · 0.45
joinMethod · 0.45
seekMethod · 0.45
writeMethod · 0.45
truncateMethod · 0.45
statMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected