You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to be able to touch files, updating their modtime timestamps. My particular application requires that there be an option to truncate the file or not upon touching it. To truncate touch it, I'm just opening it using the DELETE flag and to not truncate, I'm opening with the UPDATE flag. The former method results in the timestamp updating while the latter doesnt and attached is a simple script that demonstrates this. Is there a way to update the modtime without modifying the file, to "touch" it as its called?
from XRootD import client
from XRootD.client.flags import DirListFlags, OpenFlags, MkDirFlags, QueryCode
import time
local_server = 'YOUR LOCAL SERVER'
path = '/tmp/eggs'
with client.File() as f:
status, _ = f.open(local_server+"/"+path, OpenFlags.DELETE)
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
status, _ = f.write('green\neggs\nand\nham\n')
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
myclient = client.FileSystem(local_server)
status, deets = myclient.stat(path)
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
t1 = deets.modtime
time.sleep(1)
print(t1)
with client.File() as f:
f.open(local_server+"/"+path, OpenFlags.UPDATE)
The only way to update the modification time without actually writing to the file is to issue a truncate() request but specifying the actual size of the file. The file will not change but the mod time will be update. If you specify a size of zero then it's equivalent to opening it with the DELETE option. Of course, this is unsafe operation if other people are currently writing to the file but, based on what you say, this won't be happening.
I want to be able to touch files, updating their modtime timestamps. My particular application requires that there be an option to truncate the file or not upon touching it. To truncate touch it, I'm just opening it using the DELETE flag and to not truncate, I'm opening with the UPDATE flag. The former method results in the timestamp updating while the latter doesnt and attached is a simple script that demonstrates this. Is there a way to update the modtime without modifying the file, to "touch" it as its called?
from XRootD import client
from XRootD.client.flags import DirListFlags, OpenFlags, MkDirFlags, QueryCode
import time
local_server = 'YOUR LOCAL SERVER'
path = '/tmp/eggs'
with client.File() as f:
status, _ = f.open(local_server+"/"+path, OpenFlags.DELETE)
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
status, _ = f.write('green\neggs\nand\nham\n')
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
myclient = client.FileSystem(local_server)
status, deets = myclient.stat(path)
if not status.ok:
raise OSError(f"Something went wrong: {status.message}")
t1 = deets.modtime
time.sleep(1)
print(t1)
with client.File() as f:
f.open(local_server+"/"+path, OpenFlags.UPDATE)
status, deets = myclient.stat(path)
t2 = deets.modtime
time.sleep(1)
print(t2)
with client.File() as f:
f.open(local_server+"/"+path, OpenFlags.DELETE)
status, deets = myclient.stat(path)
t3 = deets.modtime
time.sleep(1)
print(t3)
print(t1<t2)
print(t2<t3)
assert t1 < t2 and t2 < t3
The text was updated successfully, but these errors were encountered: