Branch: Tag:

2016-04-05

2016-04-05 14:19:37 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Filesystem: Added wrapper for System.normalize_path().

Potential fix for more issues on NT.

32:   # 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 =
50:   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) + { +  path = combine_path(path); +  if (Stdio.exist(path)) { +  return System.normalize_path(path); +  } +  if (has_suffix(path, "/") && Stdio.exist(path + ".")) { +  path = System.normalize_path(path + "."); + #ifdef __NT__ +  path += "\\"; + #else +  path += "/"; + #endif +  return path; +  } +  array(string) a = path/"/"; +  int lo, hi = sizeof(a); + #ifdef __NT__ +  if (has_suffix(a[0], ":")) { +  // Avoid statting devices. +  lo = 1; +  } + #endif +  while (lo + 1 < hi) { +  int m = (lo + hi)/2; +  if (Stdio.exist(a[..m] * "/")) { +  lo = m; +  } else { +  hi = m; +  } +  } +  // NB: hi == lo + 1 here. +  path = System.normalize_path(a[..lo] * "/") + "/" + (a[hi..] * "/"); + #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);