(newbie) is_regular_file vs. symlinks in boost::filesystem ?
I'm writing code that takes a file pathname as a command-line argument. My program doesn't care whether the pathname is for a regular file, or if it's a symlink that ultimately leads to a regular file. This seems like such a common usage pattern that I would have expected Boost to have a built-in solution to this problem. But I don't see one. At the moment it looks like I'll have to write code like this: my_path = argv[1]; while (my_path is a symlink) { set my_path to the target of the symlink; error out of a cycle or excessive indirection is detected; } if (! is_regualr_file( my_path )) { tell user there's a problem; } Do I really need to write code like this?
AMDG On 09/17/2012 01:34 PM, Christian Convey wrote:
I'm writing code that takes a file pathname as a command-line argument. My program doesn't care whether the pathname is for a regular file, or if it's a symlink that ultimately leads to a regular file.
This seems like such a common usage pattern that I would have expected Boost to have a built-in solution to this problem. But I don't see one. At the moment it looks like I'll have to write code like this:
my_path = argv[1];
while (my_path is a symlink) { set my_path to the target of the symlink; error out of a cycle or excessive indirection is detected; }
if (! is_regualr_file( my_path )) { tell user there's a problem; }
Do I really need to write code like this?
According to the current (1.51) documentation, no. is_regular_file should already handle this. In Christ, Steven Watanabe
Are you sure? It looks to me like the 1.51 documentation says the
same thing as my 1.50 documentation:
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#Enum...
That makes it look like symlinks and regular files are mutually
exclusive, since they have different values in the file_type
enumeration, and is_regular_file just tests for which enumeration
value is associated with the given file's type:
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#is_r...
On Tue, Sep 18, 2012 at 12:14 AM, Steven Watanabe
AMDG
On 09/17/2012 01:34 PM, Christian Convey wrote:
I'm writing code that takes a file pathname as a command-line argument. My program doesn't care whether the pathname is for a regular file, or if it's a symlink that ultimately leads to a regular file.
This seems like such a common usage pattern that I would have expected Boost to have a built-in solution to this problem. But I don't see one. At the moment it looks like I'll have to write code like this:
my_path = argv[1];
while (my_path is a symlink) { set my_path to the target of the symlink; error out of a cycle or excessive indirection is detected; }
if (! is_regualr_file( my_path )) { tell user there's a problem; }
Do I really need to write code like this?
According to the current (1.51) documentation, no. is_regular_file should already handle this.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG On 09/18/2012 03:26 AM, Christian Convey wrote:
Are you sure? It looks to me like the 1.51 documentation says the same thing as my 1.50 documentation:
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#Enum...
That makes it look like symlinks and regular files are mutually exclusive, since they have different values in the file_type enumeration, and is_regular_file just tests for which enumeration value is associated with the given file's type:
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#is_r...
is_regular_file is defined in terms of status: http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#stat... "If possible, determines the attributes of the file p resolves to, as if by ISO/IEC 9945 stat()." In Christ, Steven Watanabe
participants (2)
-
Christian Convey
-
Steven Watanabe