32 return 0 ==
::mkdir( dir.
str().c_str() , S_IRUSR | S_IWUSR | S_IXUSR ) ;
38 if( 0 == ::stat( path , &statbuf ) )
45 enoent = error == ENOENT || error == ENOTDIR ;
53 if( 0 == ::stat( path.
str().c_str() , &statbuf ) )
55 bool x = !!( statbuf.st_mode & S_IXUSR ) ;
57 ( statbuf.st_mode & S_IFMT ) == S_IFREG ||
58 ( statbuf.st_mode & S_IFMT ) == S_IFLNK ;
70 if( 0 != ::stat( path.
str().c_str() , &statbuf ) )
71 return std::string() ;
73 std::ostringstream ss ;
74 ss << statbuf.st_size ;
81 if( 0 != ::stat( path.
str().c_str() , &statbuf ) )
82 throw TimeError( path.
str() ) ;
83 return statbuf.st_mtime ;
89 return ::stat( path.
str().c_str() , &statbuf ) == 0 ? statbuf.st_mtime : 0 ;
94 mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR ;
96 if( 0 == ::stat( path.
str().c_str() , &statbuf ) )
98 G_DEBUG(
"G::File::chmodx: old: " << statbuf.st_mode ) ;
99 mode = statbuf.st_mode | S_IXUSR ;
100 if( mode & S_IRGRP ) mode |= S_IXGRP ;
101 if( mode & S_IROTH ) mode |= S_IXOTH ;
102 G_DEBUG(
"G::File::chmodx: new: " << mode ) ;
105 bool ok = 0 == ::chmod( path.
str().c_str() , mode ) ;
106 if( !ok && do_throw )
107 throw CannotChmod( path.
str() ) ;
113 if( !link(target,new_link,
NoThrow()) )
116 std::ostringstream ss ;
117 ss <<
"[" << new_link <<
"] -> [" << target <<
"] " "(" << error <<
")" ;
118 throw CannotLink( ss.str() ) ;
126 ssize_t rc = ::readlink( new_link.
str().c_str() , buffer ,
sizeof(buffer) ) ;
127 size_t n = rc < 0 ? size_t(0U) : static_cast<size_t>(rc) ;
128 if( rc > 0 && n !=
sizeof(buffer) )
130 std::string old_target( buffer , n ) ;
131 if( target.
str() == old_target )
135 if( exists(new_link) )
136 remove( new_link ,
NoThrow() ) ;
138 rc = ::symlink( target.
str().c_str() , new_link.
str().c_str() ) ;
std::string str() const
Returns the path string.
DateTime::EpochTime time_type
static int errno_()
Returns the process's current 'errno' value.
static bool executable(const Path &)
Returns true if the path is probably executable.
static bool exists(const Path &file)
Returns true if the file (directory, link, device etc.) exists.
static bool mkdir(const Path &dir, const NoThrow &)
Creates a directory. Returns false on error.
An overload discriminator class for File methods.
static void chmodx(const Path &file)
Makes the file executable.
static void link(const Path &target, const Path &new_link)
Creates a symlink.
static std::string sizeString(const Path &file)
Returns the file's size in string format.
A Path object represents a file system path.
static time_type time(const Path &file)
Returns the file's timestamp.