sahlberg / libnfs

NFS client library
Other
524 stars 201 forks source link

API to overwrite an existing file #397

Closed bishnu1184 closed 1 year ago

bishnu1184 commented 2 years ago

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

sahlberg commented 2 years ago

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

bishnu1184 commented 2 years ago

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.