sql: test read-write permissions for given path and raise early
maybe fix #6485
This commit is contained in:
@@ -1465,3 +1465,25 @@ def random_shuffled_copy(x: Iterable[T]) -> List[T]:
|
||||
x_copy = list(x) # copy
|
||||
random.shuffle(x_copy) # shuffle in-place
|
||||
return x_copy
|
||||
|
||||
|
||||
def test_read_write_permissions(path) -> None:
|
||||
# note: There might already be a file at 'path'.
|
||||
# Make sure we do NOT overwrite/corrupt that!
|
||||
temp_path = "%s.tmptest.%s" % (path, os.getpid())
|
||||
echo = "fs r/w test"
|
||||
try:
|
||||
# test READ permissions for actual path
|
||||
if os.path.exists(path):
|
||||
with open(path, "rb") as f:
|
||||
f.read(1) # read 1 byte
|
||||
# test R/W sanity for "similar" path
|
||||
with open(temp_path, "w", encoding='utf-8') as f:
|
||||
f.write(echo)
|
||||
with open(temp_path, "r", encoding='utf-8') as f:
|
||||
echo2 = f.read()
|
||||
os.remove(temp_path)
|
||||
except Exception as e:
|
||||
raise IOError(e) from e
|
||||
if echo != echo2:
|
||||
raise IOError('echo sanity-check failed')
|
||||
|
||||
Reference in New Issue
Block a user