File lookup?

187 views
Skip to first unread message

avi.b...@nutanix.com

unread,
Mar 22, 2016, 12:04:20 AM3/22/16
to libnfs-python
When I try to stat a file, or read it, is there a way I can directly catch the NFS3ERR_NOENT so I know the file doesn't exist. Or is there a simpler "does file exist" kind of function here?

ronnie sahlberg

unread,
Mar 22, 2016, 12:26:42 AM3/22/16
to avi.b...@nutanix.com, libnfs-python
See : libnfs.h
/*
* Sync stat(<filename>)
* Function returns
* 0 : The operation was successful.
* -errno : The command failed.
*/
EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path,
struct nfs_stat_64 *st);

So, libnfs does return errno here, but we don't check it in libnfs-python.


Here is the bug :
https://github.com/sahlberg/libnfs-python/blob/master/libnfs/__init__.py#L189
where we ignore the return value from nfs_stat64(), assume we always
are successful and can always convert to a stat dict.

Bad bug :-(


I think the pythonic way to do this is to throw an exception.
nfs_stat64() will return -ENOENT if the file does not exist.

I.e.
ret = nfs_stat64(...
if ret < 0:
if ret == -ENOENT:
throw whatever python file libraries throw for enoent



Can you create a patch for this and send me a pull request ?
> --
> You received this message because you are subscribed to the Google Groups
> "libnfs-python" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to libnfs-pytho...@googlegroups.com.
> To post to this group, send email to libnfs...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/libnfs-python/e2cb90ea-3dd5-4832-8937-e5e1698f58c5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

ronnie sahlberg

unread,
Mar 28, 2016, 5:07:52 PM3/28/16
to avi.b...@nutanix.com, libnfs-python
The path based functions should throw an exception now if ENOENT happened.

kaif khan

unread,
Jan 9, 2023, 5:09:26 AM1/9/23
to libnfs-python
If You are looking for a Python course with Data Science, Brainalyst is here for you in providing excellent
 and cost-effective Data Science courses. So quickly enroll on Brainalyst Data Science Course with Placement Guarantee and make your career in data science field.
Reply all
Reply to author
Forward
0 new messages