Roxen.git / server / modules / filesystems / filesystem.pike

version» Context lines:

Roxen.git/server/modules/filesystems/filesystem.pike:25:   #else   # define FILESYSTEM_WERR(X)   #endif      #ifdef QUOTA_DEBUG   # define QUOTA_WERR(X) werror("QUOTA: "+X+"\n")   #else   # define QUOTA_WERR(X)   #endif    - #if constant(System.normalize_path) - #define NORMALIZE_PATH(X) System.normalize_path(X) - #else /* !constant(System.normalize_path) */ - #define NORMALIZE_PATH(X) (X) - #endif /* constant(System.normalize_path) */ -  +    constant module_type = MODULE_LOCATION;   LocaleString module_name = LOCALE(51,"File systems: Normal File system");   LocaleString module_doc =   LOCALE(2,"This is the basic file system module that makes it possible "    "to mount a directory structure in the virtual file system of "    "your site.");   constant module_unique = 0;      // Statistics.   int redirects, accesses, errors, dirlists;   int puts, deletes, mkdirs, moves, chmods;    -  + #if constant(System.normalize_path) + // NB: System.normalize_path() throws errors on nonexisting files. + protected string normalize_path(string path) + { +  // Get rid of segments with ".." and ".". +  path = combine_path(path); +  +  if (Stdio.exist(path)) { +  // The easy case. +  return System.normalize_path(path); +  } +  +  if (has_suffix(path, "/") && Stdio.exist(path + ".")) { +  // The almost easy case. +  path = System.normalize_path(path + "."); + #ifdef __NT__ +  path += "\\"; + #else +  path += "/"; + #endif +  return path; +  } +  +  // Try finding a valid prefix with binary search. +  array(string) a = path/"/"; +  int lo, hi = sizeof(a); + #ifdef __NT__ +  if (has_suffix(a[0], ":")) { +  // Avoid statting devices. +  lo = 1; +  } + #endif +  while (lo < hi) { +  int m = (lo + hi)/2; +  if (Stdio.exist(a[..m] * "/")) { +  if (lo == m) break; +  lo = m; +  } else { +  hi = m; +  } +  } +  +  // NB: If hi is zero then the entire path is invalid, +  // so no need to call System.normalize_path(). +  if (hi) { +  path = System.normalize_path(a[..lo] * "/") + "/" + (a[lo+1..] * "/"); +  } +  + #ifdef __NT__ +  return replace(path, "/", "\\"); + #else +  return path; + #endif + } + #define NORMALIZE_PATH(X) normalize_path(X) + #else /* !constant(System.normalize_path) */ + #define NORMALIZE_PATH(X) (X) + #endif /* constant(System.normalize_path) */ +    protected mapping http_low_answer(int errno, string data, string|void desc)   {    mapping res = Roxen.http_low_answer(errno, data);       if (desc) {    res->rettext = desc;    }       return res;   }
Roxen.git/server/modules/filesystems/filesystem.pike:274:    internal_files = map(query("internal_files"), encode_path);       if (sizeof(path) && !has_suffix(path, "/")) path += "/";      #if constant(System.normalize_path)    if (catch {    normalized_path = System.normalize_path(path + ".");    }) {    report_error(LOCALE(1, "Path normalization of %s: %s failed.\n"),    path, mountpoint); + #ifdef __NT__ +  normalized_path = replace(path, "/", "\\"); + #else    normalized_path = path; -  + #endif    }   #else /* !constant(System.normalize_path) */    normalized_path = path;   #endif /* constant(System.normalize_path) */    if ((normalized_path != "") && !(<'/','\\'>)[normalized_path[-1]]) {   #ifdef __NT__    normalized_path += "\\";   #else /* !__NT__ */    normalized_path += "/";   #endif /* __NT__ */
Roxen.git/server/modules/filesystems/filesystem.pike:467:    return 0;    }       string oldf = f;    // Regenerate f from norm_f.    f = decode_path(replace(norm_f[sizeof(normalized_path)..], "\\", "/"));    if (has_suffix(oldf, "/") && !has_suffix(f, "/")) {    // Restore the "/" stripped by encode_path() on NT.    f += "/";    } -  -  /* Adjust not_query */ -  id->not_query = mountpoint + f; +    #endif /* constant(System.normalize_path) */    }) {    errors++;    report_error(LOCALE(0, "Path normalization failure for %O:\n"    "%s\n"),    f, describe_backtrace(err));    }    return norm_f;   }