#include <Filename.h>
Inheritance diagram for Tools::Filename:
Public Member Functions | |
Filename (String *name) | |
Filename (const char *name) | |
virtual | ~Filename (void) |
virtual String * | className (void) const |
Answer receiver class name. | |
virtual Filename * | construct (String *extra) |
virtual Filename * | construct (const char *extra) |
virtual Filename * | construct (Filename *extra) |
virtual String * | constructString (String *extra) |
virtual const char * | localName (void) const |
virtual long | hash (void) const |
Answer object hash value. | |
virtual bool | isEqual (const Object *) const |
Compare receiver with given object. | |
virtual bool | isEqual (const Object &object) const |
Compare receiver with given object. | |
virtual Filename * | asFilename (void) |
virtual String * | asString (void) const |
virtual void | beCurrentDirectory (void) |
virtual void | copyTo (Filename *destName) |
virtual void | copyTo (String *destName) |
virtual OrderedCollection * | directoryContents (void) |
virtual void | erase (void) |
Delete referenced file. | |
virtual long | fileSize (void) |
virtual void | makeDirectory (void) |
virtual void | moveTo (Filename *destName) |
virtual void | moveTo (String *destName) |
virtual void | renameTo (Filename *destName) |
virtual void | renameTo (String *destName) |
virtual OrderedCollection * | components (void) |
virtual Filename * | directory (void) |
virtual String * | extension (void) |
virtual String * | head (void) |
virtual String * | tail (void) |
virtual void | printOn (Stream *stream) |
virtual FileEncodedStreamFactory * | withEncoding (String *encoding) |
virtual FileEncodedStreamFactory * | withEncoding (const char *encoding) |
virtual ExternalWriteStream * | appendStream (void) |
virtual ExternalReadStream * | readStream (void) |
virtual ExternalReadAppendStream * | readAppendStream (void) |
virtual ExternalWriteStream * | writeStream (void) |
virtual bool | exists (void) |
virtual bool | isAbsolute (void) |
virtual bool | isDirectory (void) |
virtual bool | isReadable (void) |
virtual bool | isRelative (void) |
virtual bool | isWritable (void) |
virtual ByteArray * | contentOfEntireFile (void) |
virtual OrderedCollection * | filesMatchingAccessList (OrderedCollection *list, OrderedCollection *result) |
virtual long | lastSeparatorIndex (void) |
virtual void | privateCopy (FileAccessor *read, FileAccessor *write) |
virtual OrderedCollection * | privFilesMatchingAccessList (OrderedCollection *list, OrderedCollection *result) |
Static Public Member Functions | |
static Character * | separator (void) |
static Filename * | currentDirectory (void) |
Answer current working directory. | |
static String * | currentDirectoryString (void) |
static OrderedCollection * | filesMatching (String *pattern) |
static bool | isCaseSensitive (void) |
static Filename * | baseDirectoryForList (OrderedCollection *list) |
static String * | readBaseLocationFromStream (PositionableStream *stream) |
static OrderedCollection * | components (String *name) |
static void | setCurrentDirectory (Filename *directory) |
Protected Attributes | |
String * | public_name |
char * | local_name |
|
Definition at line 50 of file Filename.cc. References Core::String::asCString(), local_name, and public_name. Referenced by baseDirectoryForList(), construct(), copyTo(), currentDirectory(), directory(), moveTo(), and renameTo(). 00051 { 00052 public_name = name; 00053 local_name = public_name->asCString(); 00054 }
|
|
Definition at line 56 of file Filename.cc. References Core::String::asCString(), local_name, and public_name. 00057 { 00058 public_name = new String(name); 00059 local_name = public_name->asCString(); 00060 }
|
|
Definition at line 62 of file Filename.cc. References local_name. 00063 { 00064 GC_free(local_name); 00065 }
|
|
Definition at line 359 of file Filename.cc. References public_name, and Core::IOAccessor::writeStream(). Referenced by Tools::FileEncodedStreamFactory::appendStream(). 00360 { 00361 FileAccessor *accessor; 00362 accessor = new FileAccessor(public_name, O_WRONLY, O_APPEND | O_CREAT); 00363 return accessor->writeStream(); 00364 }
|
|
Definition at line 171 of file Filename.cc. 00172 { 00173 return this; 00174 }
|
|
Definition at line 176 of file Filename.cc. References public_name. Referenced by components(), construct(), constructString(), copyTo(), hash(), head(), isEqual(), lastSeparatorIndex(), privFilesMatchingAccessList(), and tail(). 00177 { 00178 return public_name; 00179 }
|
|
Definition at line 267 of file Filename.cc. References currentDirectory(), Filename(), Core::OrderedCollection::first(), Core::OrderedCollection::removeFirst(), and separator(). Referenced by filesMatching(). 00268 { 00269 if (dynamic_cast<String *>(list->first())->first()->isEqual(separator())) { 00270 return new Filename(dynamic_cast<String *>(list->removeFirst())); 00271 } else { 00272 return currentDirectory(); 00273 } 00274 }
|
|
Definition at line 182 of file Filename.cc. References Core::Object::error(), exists(), isDirectory(), and setCurrentDirectory(). 00183 { 00184 if (!(exists() && isDirectory())) { 00185 error(new String("Receiver must be an existing directory."), 00186 new String(__PRETTY_FUNCTION__)); 00187 } 00188 setCurrentDirectory(this); 00189 }
|
|
Answer receiver class name. Because there isn't any standard way to obtain class name this method comes to place. Every class should rewrite this method but many didn't (yet). Reimplemented from Core::Object. Definition at line 68 of file Filename.cc. Referenced by isEqual(). 00069 { 00070 return new String("Filename"); 00071 }
|
|
Definition at line 292 of file Filename.cc. References Core::OrderedCollection::add(), Core::PositionableStream::atEnd(), components(), Core::Collection::isEmpty(), readBaseLocationFromStream(), Core::SequenceableCollection::readStream(), separator(), and Core::Stream::upTo(). 00293 { 00294 OrderedCollection *components = new OrderedCollection; 00295 ReadStream *stream = name->readStream(); 00296 00297 String *component = readBaseLocationFromStream(stream); 00298 if (!component->isEmpty()) components->add(component); 00299 while (!stream->atEnd()) 00300 components->add(stream->upTo(separator())); 00301 return components; 00302 }
|
|
Definition at line 287 of file Filename.cc. References asString(). Referenced by components(), and filesMatching(). 00288 { 00289 return components(asString()); 00290 }
|
|
Definition at line 84 of file Filename.cc. References asString(), and construct().
|
|
Definition at line 79 of file Filename.cc. References construct().
|
|
Definition at line 74 of file Filename.cc. References constructString(), and Filename(). Referenced by construct(), filesMatchingAccessList(), and privFilesMatchingAccessList(). 00075 { 00076 return new Filename(constructString(extra)); 00077 }
|
|
Definition at line 89 of file Filename.cc. References asString(), Core::Stream::contents(), Core::String::copy(), Core::SequenceableCollection::first(), Core::Collection::isEmpty(), Core::Stream::nextPut(), Core::Stream::nextPutAll(), separator(), and Core::String::size(). Referenced by construct(). 00090 { 00091 Character *sep = separator(); 00092 String *prefix = asString(); 00093 String *suffix; 00094 Stream *ws; 00095 if (!extra->isEmpty() && extra->first()->isEqual(sep)) { 00096 suffix = dynamic_cast<String *>(extra->copy(1, extra->size())); 00097 } else { 00098 suffix = extra; 00099 } 00100 ws = (new String(prefix->size() + suffix->size() + 1))->writeStream(); 00101 ws->nextPutAll(prefix); 00102 if (prefix->isEmpty() || !prefix->first()->isEqual(sep)) { 00103 ws->nextPut(sep); 00104 } 00105 ws->nextPutAll(suffix); 00106 return dynamic_cast<String *>(ws->contents()); 00107 }
|
|
Definition at line 432 of file Filename.cc. References _ensure, Core::Stream::close(), Core::Stream::contents(), and readStream(). 00433 { 00434 Stream *stream; 00435 ByteArray *content; 00436 00437 _ensure( 00438 stream = readStream(); 00439 content = dynamic_cast<ByteArray *>(stream->contents()) 00440 , 00441 stream->close() 00442 ); 00443 00444 return content; 00445 }
|
|
Definition at line 198 of file Filename.cc. References copyTo(), and Filename().
|
|
Definition at line 191 of file Filename.cc. References asString(), localName(), and privateCopy(). Referenced by copyTo(), and moveTo(). 00192 { 00193 if (link(localName(), destName->localName()) == 0) return; 00194 privateCopy(FileAccessor::openFileReadOnly(asString()), 00195 FileAccessor::openFileWriteOnly(destName->asString())); 00196 }
|
|
Answer current working directory. It can answer either relative or absolute path. Definition at line 116 of file Filename.cc. References currentDirectoryString(), and Filename(). Referenced by baseDirectoryForList(). 00117 { 00118 return new Filename(currentDirectoryString()); 00119 }
|
|
Definition at line 121 of file Filename.cc. Referenced by currentDirectory(), and head(). 00122 { 00123 char *buffer = getcwd(NULL, 0); 00124 String *fn = new String(buffer); 00125 free((void *) buffer); 00126 return fn; 00127 }
|
|
Definition at line 304 of file Filename.cc. References Filename(), and head().
|
|
Definition at line 203 of file Filename.cc. References Core::OrderedCollection::add(), and localName(). Referenced by privFilesMatchingAccessList(). 00204 { 00205 OrderedCollection *allFiles = new OrderedCollection; 00206 DIR *dir; 00207 struct dirent *entry; 00208 00209 dir = opendir(localName()); 00210 if (dir == NULL) return allFiles; 00211 while ((entry = readdir(dir)) != NULL) { 00212 allFiles->add(new String(entry->d_name)); 00213 } 00214 closedir(dir); 00215 return allFiles; 00216 }
|
|
Delete referenced file. Obviously this cannot be called 'delete'. Definition at line 218 of file Filename.cc. References Core::Object::error(), and localName(). Referenced by moveTo(). 00219 { 00220 int retCode = remove(localName()); 00221 if (retCode < 0) { 00222 error(new String("Unexpected error"), 00223 new String(__PRETTY_FUNCTION__)); 00224 } 00225 }
|
|
Definition at line 384 of file Filename.cc. References localName(). Referenced by beCurrentDirectory(), and privFilesMatchingAccessList(). 00385 { 00386 struct stat buf; 00387 00388 return stat(localName(), &buf) == 0; 00389 }
|
|
Definition at line 309 of file Filename.cc. References Core::String::copy(), Core::String::lastIndexOf(), nil, Core::String::size(), and tail(). 00310 { 00311 String *t = tail(); 00312 int periodIndex = t->lastIndexOf('.'); 00313 if (periodIndex <= 0) return nil; 00314 return dynamic_cast<String *>(t->copy(periodIndex, t->size())); 00315 }
|
|
Definition at line 227 of file Filename.cc. References localName(). 00228 { 00229 struct stat buf; 00230 00231 stat(localName(), &buf); 00232 return buf.st_size; 00233 }
|
|
Definition at line 130 of file Filename.cc. References baseDirectoryForList(), components(), and Core::Collection::isEmpty(). 00131 { 00132 OrderedCollection *allFiles = new OrderedCollection; 00133 OrderedCollection *list = components(pattern); 00134 00135 if (list->isEmpty()) return allFiles; 00136 baseDirectoryForList(list)->filesMatchingAccessList(list, allFiles); 00137 return allFiles; 00138 }
|
|
Definition at line 448 of file Filename.cc. References construct(), privFilesMatchingAccessList(), and Core::OrderedCollection::removeFirst(). Referenced by privFilesMatchingAccessList(). 00450 { 00451 if (list->isEmpty()) return result; 00452 if (dynamic_cast<String *>(list->first())->isEqual(".")) { 00453 list->removeFirst(); 00454 return filesMatchingAccessList(list, result); 00455 } 00456 if (dynamic_cast<String *>(list->first())->isEqual("..")) { 00457 list->removeFirst(); 00458 return (construct("..")->filesMatchingAccessList(list, result)); 00459 } 00460 return privFilesMatchingAccessList(list, result); 00461 }
|
|
Answer object hash value. The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too. Reimplemented from Core::Object. Definition at line 153 of file Filename.cc. References asString(). 00154 { 00155 return asString()->asUppercase()->hash(); 00156 }
|
|
Definition at line 317 of file Filename.cc. References asString(), currentDirectoryString(), and lastSeparatorIndex(). Referenced by directory(). 00318 { 00319 long index = lastSeparatorIndex(); 00320 if (index >= 0) { 00321 index = (index > 1) ? index : 1; 00322 return dynamic_cast<String *>(asString()->copy(0, index)); 00323 } else { 00324 return currentDirectoryString(); 00325 } 00326 }
|
|
Definition at line 391 of file Filename.cc. References Core::SequenceableCollection::first(), Core::Collection::isEmpty(), public_name, and separator(). Referenced by isRelative(). 00392 { 00393 if (public_name->isEmpty()) return false; 00394 return public_name->first()->isEqual(separator()); 00395 }
|
|
Definition at line 141 of file Filename.cc. Referenced by isEqual(), and privFilesMatchingAccessList(). 00142 { 00143 return true; 00144 }
|
|
Definition at line 397 of file Filename.cc. References localName(). Referenced by beCurrentDirectory(), and privFilesMatchingAccessList(). 00398 { 00399 struct stat buf; 00400 00401 stat(localName(), &buf); 00402 return S_ISDIR(buf.st_mode); 00403 }
|
|
Compare receiver with given object. Do not rewrite this method. It just a sugar for Object::isEqual(Object *).
Reimplemented from Core::Object. Definition at line 84 of file Filename.h. 00085 { return Object::isEqual(object); }
|
|
Compare receiver with given object. This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so). If you rewrite this method you should rewrite hash() too.
Reimplemented from Core::Object. Definition at line 158 of file Filename.cc. References asString(), className(), Core::Object::className(), and isCaseSensitive(). 00159 { 00160 if (!obj->className()->isEqual(className())) return false; 00161 const Filename *fn = dynamic_cast<const Filename *>(obj); 00162 if (isCaseSensitive()) { 00163 return asString()->isEqual(fn->asString()); 00164 } else { 00165 // return asString()->sameAs(fn->asString()); 00166 return asString()->asUppercase()->isEqual(fn->asString()->asUppercase()); 00167 } 00168 }
|
|
Definition at line 405 of file Filename.cc. References localName(). 00406 { 00407 struct stat buf; 00408 int mask; 00409 00410 stat(localName(), &buf); 00411 mask = S_IROTH & ((getegid() == buf.st_gid) ? S_IRGRP : 0) 00412 & ((geteuid() == buf.st_uid) ? S_IRUSR : 0); 00413 return (buf.st_mode & mask) != 0; 00414 }
|
|
Definition at line 416 of file Filename.cc. References isAbsolute(). 00417 { 00418 return !isAbsolute(); 00419 }
|
|
Definition at line 421 of file Filename.cc. References localName(). 00422 { 00423 struct stat buf; 00424 int mask; 00425 00426 stat(localName(), &buf); 00427 mask = S_IWOTH & ((getegid() == buf.st_gid) ? S_IWGRP : 0) 00428 & ((geteuid() == buf.st_uid) ? S_IWUSR : 0); 00429 return (buf.st_mode & mask) != 0; 00430 }
|
|
Definition at line 463 of file Filename.cc. References asString(), and separator(). Referenced by head(), and tail().
|
|
Definition at line 147 of file Filename.cc. References local_name. Referenced by copyTo(), directoryContents(), erase(), exists(), fileSize(), isDirectory(), isReadable(), isWritable(), makeDirectory(), renameTo(), and setCurrentDirectory(). 00148 { 00149 return local_name; 00150 }
|
|
Definition at line 235 of file Filename.cc. References Core::Object::error(), and localName(). 00236 { 00237 int retCode = mkdir(localName(), 0777); 00238 if (retCode < 0) { 00239 error(new String("Unexpected error"), 00240 new String(__PRETTY_FUNCTION__)); 00241 } 00242 }
|
|
Definition at line 250 of file Filename.cc. References Filename(), and moveTo().
|
|
Definition at line 244 of file Filename.cc. References copyTo(), and erase(). Referenced by moveTo(), and renameTo().
|
|
Definition at line 340 of file Filename.cc. References Core::Stream::nextPut(), Core::Stream::print(), and public_name. 00341 { 00342 Object::printOn(stream); 00343 stream->nextPut('('); 00344 stream->print(public_name); 00345 stream->nextPut(')'); 00346 }
|
|
Definition at line 468 of file Filename.cc. References _ensure, Core::IOAccessor::bufferSize(), Core::FileAccessor::close(), Core::FileAccessor::readInto(), and Core::FileAccessor::writeFrom(). Referenced by copyTo(). 00469 { 00470 int bufSize = source->bufferSize(); 00471 ByteArray *buffer = new ByteArray(bufSize); 00472 int amountRead; 00473 00474 _ensure ( 00475 while ((amountRead = source->readInto(buffer)) > 0) { 00476 destination->writeFrom(buffer, 0, amountRead); 00477 } 00478 , 00479 source->close(); 00480 destination->close(); 00481 ); 00482 }
|
|
Definition at line 484 of file Filename.cc. References Core::OrderedCollection::add(), asString(), Core::OrderedCollection::at(), construct(), directoryContents(), exists(), filesMatchingAccessList(), Core::String::includes(), isCaseSensitive(), isDirectory(), Core::Collection::isEmpty(), Core::String::match(), and Core::OrderedCollection::size(). Referenced by filesMatchingAccessList(). 00486 { 00487 Filename *fullname; 00488 String *pref = dynamic_cast<String *>(list->first()); 00489 OrderedCollection *sublist; 00490 00491 sublist = dynamic_cast<OrderedCollection *>(list->copy(1, list->size())); 00492 if (!(pref->includes('*') || pref->includes('#'))) { 00493 fullname = construct(pref); 00494 if (sublist->isEmpty()) { 00495 if (fullname->exists()) result->add(fullname->asString()); 00496 } else { 00497 if (fullname->exists() && fullname->isDirectory()) 00498 filesMatchingAccessList(sublist, result); 00499 } 00500 return result; 00501 } 00502 00503 OrderedCollection *contents = directoryContents(); 00504 int length = contents->size(); 00505 for (int i = 0; i < length; i++) { 00506 String *name = dynamic_cast<String *>(contents->at(i)); 00507 if (pref->match(name, !isCaseSensitive())) { 00508 fullname = construct(name); 00509 if (sublist->isEmpty()) { 00510 result->add(fullname->asString()); 00511 } else { 00512 if (fullname->isDirectory()) 00513 filesMatchingAccessList(sublist, result); 00514 } 00515 } 00516 } 00517 return result; 00518 }
|
|
Definition at line 371 of file Filename.cc. References public_name, and Core::IOAccessor::readAppendStream(). 00372 { 00373 FileAccessor *accessor; 00374 accessor = new FileAccessor(public_name, O_RDWR, O_APPEND | O_CREAT); 00375 return accessor->readAppendStream(); 00376 }
|
|
Definition at line 276 of file Filename.cc. References Core::PositionableStream::peekFor(), and separator(). Referenced by components(). 00277 { 00278 if (stream->peekFor(separator())) { 00279 if (stream->peekFor(separator())) { 00280 return String::with(separator(), separator()); 00281 } 00282 return String::with(separator()); 00283 } 00284 return new String; 00285 }
|
|
Definition at line 366 of file Filename.cc. References public_name. Referenced by contentOfEntireFile(), and Tools::FileEncodedStreamFactory::readStream(). 00367 { 00368 return FileAccessor::openFileReadOnly(public_name)->readStream(); 00369 }
|
|
Definition at line 261 of file Filename.cc. References Filename(), and renameTo().
|
|
Definition at line 255 of file Filename.cc. References localName(), and moveTo(). Referenced by renameTo(). 00256 { 00257 if (rename(localName(), destName->localName()) == 0) return; 00258 moveTo(destName); 00259 }
|
|
Definition at line 110 of file Filename.cc. Referenced by baseDirectoryForList(), components(), constructString(), isAbsolute(), lastSeparatorIndex(), and readBaseLocationFromStream(). 00111 { 00112 return Character::value('/'); 00113 }
|
|
Definition at line 520 of file Filename.cc. References localName(). Referenced by beCurrentDirectory(). 00521 { 00522 int retCode = chdir(directory->localName()); 00523 if (retCode < 0) { 00524 (new Error(new String("Unexpected error"), 00525 new String(__PRETTY_FUNCTION__), 00526 directory))->raise(); 00527 } 00528 }
|
|
Definition at line 328 of file Filename.cc. References asString(), Core::String::copy(), lastSeparatorIndex(), and Core::String::size(). Referenced by extension(). 00329 { 00330 String *nm = asString(); 00331 long index = lastSeparatorIndex(); 00332 if (index >= 0) { 00333 return dynamic_cast<String *>(nm->copy(index + 1, nm->size())); 00334 } else { 00335 return dynamic_cast<String *>(nm->copy()); 00336 } 00337 }
|
|
Definition at line 354 of file Filename.cc. References withEncoding(). 00355 { 00356 return withEncoding(new String(encoding)); 00357 }
|
|
Definition at line 349 of file Filename.cc. Referenced by Tools::LogWriter::on(), and withEncoding(). 00350 { 00351 return new FileEncodedStreamFactory(this, encoding); 00352 }
|
|
Definition at line 378 of file Filename.cc. References public_name. Referenced by Tools::FileEncodedStreamFactory::writeStream(). 00379 { 00380 return FileAccessor::openFileWriteOnly(public_name)->writeStream(); 00381 }
|
|
Definition at line 46 of file Filename.h. Referenced by Filename(), localName(), and ~Filename(). |
|
Definition at line 45 of file Filename.h. Referenced by appendStream(), asString(), Filename(), isAbsolute(), printOn(), readAppendStream(), readStream(), and writeStream(). |