X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fstat.cpp;h=716a7d6a4f82707587aed2a9b452aa4bde87715c;hp=d11867d99b6af41a427dba423673acc622390a65;hb=5a006c4fce0893b63f881a6c9ecd010f15770428;hpb=3ba7e8ca4cc6a2c77028d49687d29364f9e1ca26 diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp index d11867d..716a7d6 100644 --- a/source/fs/stat.cpp +++ b/source/fs/stat.cpp @@ -3,6 +3,7 @@ #include #else #define _FILE_OFFSET_BITS 64 +#include #include #include #include @@ -46,6 +47,7 @@ struct Stat::Private Stat Stat::Private::from_struct_stat(const struct stat &st) { Stat result; + result.exists = true; if(S_ISREG(st.st_mode)) result.type = REGULAR; else if(S_ISDIR(st.st_mode)) @@ -79,6 +81,7 @@ Stat Stat::Private::from_struct_stat(const struct stat &st) #endif Stat::Stat(): + exists(false), type(UNKNOWN), size(0), alloc_size(0) @@ -132,7 +135,12 @@ Stat Stat::stat(const Path &path) struct stat st; int ret = ::stat(path.str().c_str(), &st); if(ret==-1) - throw system_error("stat"); + { + if(errno==ENOENT) + return Stat(); + else + throw system_error("stat"); + } return Private::from_struct_stat(st); #endif @@ -146,7 +154,12 @@ Stat Stat::lstat(const Path &path) struct stat st; int ret = ::lstat(path.str().c_str(), &st); if(ret==-1) - throw system_error("lstat"); + { + if(errno==ENOENT) + return Stat(); + else + throw system_error("lstat"); + } return Private::from_struct_stat(st); #endif