libnfs icon indicating copy to clipboard operation
libnfs copied to clipboard

API to overwrite an existing file

Open bishnu1184 opened this issue 3 years ago • 2 comments

Hi Ronnie, I want to overwrite an existing file on NFS share with new file, so that content of the file gets updated but all its permission and ACLs will remain same as of original file. Hence I wanted to know if there is any API or way in libNFS by which I can do the same.

Thanks, Bishnu

bishnu1184 avatar Oct 04 '22 06:10 bishnu1184

nfs_open* with the flag O_TRUNC should do that. That will truncate the file when you open it.

sahlberg avatar Oct 04 '22 07:10 sahlberg

Thanks, it worked. I was trying to pass O_TRUNC in nfs_create* so that if the file doesn't exist then it will create that and if it exist then it should truncate the existing file. But I was always getting error EEXIST for existing file. So I think I will have to add error code check and based on that I will have to call nfs_create* or nfs_open* APIs.

bishnu1184 avatar Oct 04 '22 08:10 bishnu1184