X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=nucleus%2Flibrary%2Ffilesystem%2Ffilename.cpp;h=adca7e99dcee76d0d31b12f473c455897d594d95;hb=c160b4bac86a40cf5ce4fc0dcdab69afc5edad2f;hp=6c87f99d3f4a13f43db4575f94079ccd44289f35;hpb=293f927b59ff6a34067e7cf37c00d1a4291095a1;p=feisty_meow.git diff --git a/nucleus/library/filesystem/filename.cpp b/nucleus/library/filesystem/filename.cpp index 6c87f99d..adca7e99 100644 --- a/nucleus/library/filesystem/filename.cpp +++ b/nucleus/library/filesystem/filename.cpp @@ -189,28 +189,32 @@ void filename::canonicalize() + astring(DEFAULT_SEPARATOR, 1)); // must be at least as long as the string we're looking for, plus a drive letter afterwards. if ( (length() > CYGDRIVE_PATH.length() + 1) && begins(CYGDRIVE_PATH) ) { - zap(0, CYGDRIVE_PATH.length() + 1); // whack the cygdrive portion plus two slashes. + zap(0, CYGDRIVE_PATH.length() - 1); // whack the cygdrive portion plus two slashes. insert(1, ":"); // add a colon after the imputed drive letter. +LOG(astring("turned cygdrive string into: ") + *this); } // now we convert msys... - if ( (length() >= 2) && (get(0) == DEFAULT_SEPARATOR) && textual::parser_bits::is_alpha(get(1)) ) { + if ( (length() >= 2) && (get(0) == DEFAULT_SEPARATOR) + && textual::parser_bits::is_alpha(get(1)) ) { // we seem reasonably sure now that this is a windows path hiding in msys format, but // the next character needs to be a slash (if there is a next character) for it to be // the windows drive form. otherwise it could be /tmp, which would obviously not be // intended as a windows path. - if ( (length() < 3) || (get(2) == DEFAULT_SEPARATOR) ) { + if ( (length() == 2) || (get(2) == DEFAULT_SEPARATOR) ) { // cool, this should be interpretable as an msys path, except for those wacky types - // that use top-level single character directory names. we cannot help that, because - // we *know* msys is a choice used in other code a lot. -//hmmm: future revision: see if the file or directory '/x' actually exists on current drive? yuck. + // of folks that might use a top-level single character directory name. we cannot + // help them, because we have made a design decision to support msys-style paths. + // note that this would only affect someone if they were referring to their directory on + // the current windows partition (c:, d:, etc.) without providing the drive letter, + // if they had that single character directory name (e.g., c:\x, d:\q, etc.) and even + // then only on the near defunct windows platform. zap(0, 0); // take off initial slash. insert(1, ":"); // add the obligatory colon. +LOG(astring("turned msys string into: ") + *this); } } #endif -LOG(astring("ha ha turned string into: ") + *this); - // we don't crop the last separator if the name's too small. for msdos // names, that would be chopping a slash off the c:\ style name. if (length() > 3) { @@ -300,6 +304,18 @@ bool filename::is_executable() const return !!(fill.st_mode & S_IEXEC); } +bool filename::is_normal() const +{ + status_info fill; + if (!get_info(&fill)) + return false; + bool weird = S_ISCHR(fill.st_mode) + || S_ISBLK(fill.st_mode) + || S_ISFIFO(fill.st_mode) + || S_ISSOCK(fill.st_mode); + return !weird; +} + int filename::find_last_separator(const astring &look_at) const { int last_sep = -1; @@ -418,7 +434,7 @@ void filename::separate(string_array &pieces) const if (separator(raw_form[i])) { // this is a separator character, so eat it and add the accumulated // string to the list. - if (!i || accumulator.length()) pieces += accumulator; + if (i && accumulator.length()) pieces += accumulator; // now reset our accumulated text. accumulator = astring::empty_string(); } else {