00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "nfileinfo.h"
00023
00024
00025
00026
00027
00028
00029 NFileInfo::NFileInfo(const NString &path)
00030 : NObject(),
00031 m_path(path)
00032 {
00033
00034 }
00035
00036 NFileInfo::~NFileInfo(void) {
00037
00038 }
00039
00040 bool NFileInfo::isFile(void) const {
00041 return NFileInfo::isFile(m_path);
00042 }
00043
00044
00045 bool NFileInfo::isDir(void) const {
00046 return NFileInfo::isDir(m_path);
00047 }
00048
00049
00050 bool NFileInfo::isDevice(void) const {
00051 return NFileInfo::isDevice(m_path);
00052 }
00053
00054
00055 bool NFileInfo::isFifo(void) const {
00056 return NFileInfo::isFifo(m_path);
00057 }
00058
00059
00060 bool NFileInfo::isLink(void) const {
00061 return NFileInfo::isLink(m_path);
00062 }
00063
00064 bool NFileInfo::exists(void) const {
00065 return NFileInfo::exists(m_path);
00066 }
00067
00068 bool NFileInfo::ownerRead(void) const {
00069 return NFileInfo::ownerRead(m_path);
00070 }
00071
00072
00073 bool NFileInfo::groupRead(void) const {
00074 return NFileInfo::groupRead(m_path);
00075 }
00076
00077
00078 bool NFileInfo::othersRead(void) const {
00079 return NFileInfo::othersRead(m_path);
00080 }
00081
00082
00083 bool NFileInfo::ownerWrite(void) const {
00084 return NFileInfo::ownerWrite(m_path);
00085 }
00086
00087
00088 bool NFileInfo::groupWrite(void) const {
00089 return NFileInfo::groupWrite(m_path);
00090 }
00091
00092
00093 bool NFileInfo::othersWrite(void) const {
00094 return NFileInfo::othersWrite(m_path);
00095 }
00096
00097
00098 bool NFileInfo::ownerExecute(void) const {
00099 return NFileInfo::ownerExecute(m_path);
00100 }
00101
00102
00103 bool NFileInfo::groupExecute(void) const {
00104 return NFileInfo::groupExecute(m_path);
00105 }
00106
00107
00108 bool NFileInfo::othersExecute(void) const {
00109 return NFileInfo::othersExecute(m_path);
00110 }
00111
00112 bool NFileInfo::isFile(const NString &path) {
00113 struct stat sb;
00114
00115 if (stat(path.toChar(), &sb) == -1) {
00116 throw NIOException(nerror(errno), path,
00117 NException::BASEIO,
00118 NIOException::FILE,
00119 errno);
00120 }
00121
00122 if ((sb.st_mode & S_IFMT) == S_IFREG) {
00123 return true;
00124 }
00125
00126 return false;
00127 }
00128
00129
00130 bool NFileInfo::isDir(const NString &path) {
00131 struct stat sb;
00132
00133 if (stat(path.toChar(), &sb) == -1) {
00134 throw NIOException(nerror(errno), path,
00135 NException::BASEIO,
00136 NIOException::FILE,
00137 errno);
00138 }
00139
00140 if ((sb.st_mode & S_IFMT) == S_IFDIR) {
00141 return true;
00142 }
00143
00144 return false;
00145 }
00146
00147
00148 bool NFileInfo::isDevice(const NString &path) {
00149 struct stat sb;
00150
00151 if (stat(path.toChar(), &sb) == -1) {
00152 throw NIOException(nerror(errno), path,
00153 NException::BASEIO,
00154 NIOException::FILE,
00155 errno);
00156 }
00157
00158 if ((sb.st_mode & S_IFMT) == S_IFCHR) {
00159 return true;
00160 }
00161
00162 return false;
00163 }
00164
00165
00166 bool NFileInfo::isFifo(const NString &path) {
00167 struct stat sb;
00168
00169 if (stat(path.toChar(), &sb) == -1) {
00170 throw NIOException(nerror(errno), path,
00171 NException::BASEIO,
00172 NIOException::FILE,
00173 errno);
00174 }
00175
00176 if ((sb.st_mode & S_IFMT) == S_IFIFO) {
00177 return true;
00178 }
00179
00180 return false;
00181 }
00182
00183
00184 bool NFileInfo::isLink(const NString &path) {
00185 struct stat sb;
00186
00187 if (stat(path.toChar(), &sb) == -1) {
00188 throw NIOException(nerror(errno), path,
00189 NException::BASEIO,
00190 NIOException::FILE,
00191 errno);
00192 }
00193
00194 if ((sb.st_mode & S_IFMT) == S_IFLNK) {
00195 return true;
00196 }
00197
00198 return false;
00199 }
00200
00201
00202 bool NFileInfo::exists(const NString &path) {
00203 struct stat sb;
00204
00205 if (stat(path.toChar(), &sb) == -1) {
00206 if (errno == ENOENT) {
00207 return false;
00208 }
00209 throw NIOException(nerror(errno), path,
00210 NException::BASEIO,
00211 NIOException::FILE,
00212 errno);
00213 }
00214
00215 return true;
00216 }
00217
00218
00219 bool NFileInfo::ownerRead(const NString &path) {
00220 struct stat sb;
00221
00222 if (stat(path.toChar(), &sb) == -1) {
00223 throw NIOException(nerror(errno), path,
00224 NException::BASEIO,
00225 NIOException::FILE,
00226 errno);
00227 }
00228
00229 if (sb.st_mode & S_IRUSR) {
00230 return true;
00231 }
00232
00233 return false;
00234 }
00235
00236
00237 bool NFileInfo::groupRead(const NString &path) {
00238 struct stat sb;
00239
00240 if (stat(path.toChar(), &sb) == -1) {
00241 throw NIOException(nerror(errno), path,
00242 NException::BASEIO,
00243 NIOException::FILE,
00244 errno);
00245 }
00246
00247 if (sb.st_mode & S_IRGRP) {
00248 return true;
00249 }
00250
00251 return false;
00252 }
00253
00254
00255 bool NFileInfo::othersRead(const NString &path) {
00256 struct stat sb;
00257
00258 if (stat(path.toChar(), &sb) == -1) {
00259 throw NIOException(nerror(errno), path,
00260 NException::BASEIO,
00261 NIOException::FILE,
00262 errno);
00263 }
00264
00265 if (sb.st_mode & S_IROTH) {
00266 return true;
00267 }
00268
00269 return false;
00270 }
00271
00272
00273 bool NFileInfo::ownerWrite(const NString &path) {
00274 struct stat sb;
00275
00276 if (stat(path.toChar(), &sb) == -1) {
00277 throw NIOException(nerror(errno), path,
00278 NException::BASEIO,
00279 NIOException::FILE,
00280 errno);
00281 }
00282
00283 if (sb.st_mode & S_IWUSR) {
00284 return true;
00285 }
00286
00287 return false;
00288 }
00289
00290
00291 bool NFileInfo::groupWrite(const NString &path) {
00292 struct stat sb;
00293
00294 if (stat(path.toChar(), &sb) == -1) {
00295 throw NIOException(nerror(errno), path,
00296 NException::BASEIO,
00297 NIOException::FILE,
00298 errno);
00299 }
00300
00301 if (sb.st_mode & S_IWGRP) {
00302 return true;
00303 }
00304
00305 return false;
00306 }
00307
00308
00309 bool NFileInfo::othersWrite(const NString &path) {
00310 struct stat sb;
00311
00312 if (stat(path.toChar(), &sb) == -1) {
00313 throw NIOException(nerror(errno), path,
00314 NException::BASEIO,
00315 NIOException::FILE,
00316 errno);
00317 }
00318
00319 if (sb.st_mode & S_IWOTH) {
00320 return true;
00321 }
00322
00323 return false;
00324 }
00325
00326
00327 bool NFileInfo::ownerExecute(const NString &path) {
00328 struct stat sb;
00329
00330 if (stat(path.toChar(), &sb) == -1) {
00331 throw NIOException(nerror(errno), path,
00332 NException::BASEIO,
00333 NIOException::FILE,
00334 errno);
00335 }
00336
00337 if ((sb.st_mode & S_IRWXU) == S_IXUSR) {
00338 return true;
00339 }
00340
00341 return false;
00342 }
00343
00344
00345 bool NFileInfo::groupExecute(const NString &path) {
00346 struct stat sb;
00347
00348 if (stat(path.toChar(), &sb) == -1) {
00349 throw NIOException(nerror(errno), path,
00350 NException::BASEIO,
00351 NIOException::FILE,
00352 errno);
00353 }
00354
00355 if (sb.st_mode & S_IXGRP) {
00356 return true;
00357 }
00358
00359 return false;
00360 }
00361
00362
00363 bool NFileInfo::othersExecute(const NString &path) {
00364 struct stat sb;
00365
00366 if (stat(path.toChar(), &sb) == -1) {
00367 throw NIOException(nerror(errno), path,
00368 NException::BASEIO,
00369 NIOException::FILE,
00370 errno);
00371 }
00372
00373 if (sb.st_mode & S_IXOTH) {
00374 return true;
00375 }
00376
00377 return false;
00378 }