Branch: Tag:

2004-05-12

2004-05-12 12:06:44 by Martin Stjernholm <mast@lysator.liu.se>

Fix in recurse_delete_file.

Rev: server/base_server/module.pike:1.197

1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2001, Roxen IS. - // $Id: module.pike,v 1.196 2004/05/10 21:37:30 mast Exp $ + // $Id: module.pike,v 1.197 2004/05/12 12:06:44 mast Exp $      #include <module_constants.h>   #include <module.h>
1143:   mapping(string:mixed)|int(-1..0)|Stdio.File find_file(string path,    RequestID id);    - //! Delete the file specified by @[path]. It's unspecified if it works - //! recursively or not. + //! Delete the file specified by @[path].   //! - //! @note - //! Should return a 204 status on success. + //! It's unspecified if it works recursively or not, but if it does + //! then it has to check DAV locks through @[write_access] + //! recursively.   //! -  + //! @returns + //! Returns a 204 status on success, 0 if the file doesn't exist, or + //! an appropriate status mapping for any other error. + //!   //! @note   //! The default implementation falls back to @[find_file()].   mapping(string:mixed) delete_file(string path, RequestID id)
1171:    RequestID id,    void|MultiStatus.Prefixed stat)   { +  SIMPLE_TRACE_ENTER (this, "Deleting %O recursively", path);    if (!stat)    id->get_multi_status()->prefix (id->url_base() + query_location()[1..]);    -  mapping(string:mixed) recurse (string path) -  { +     Stat st = stat_file(path, id); -  if (!st) return 0; +  if (!st) { +  SIMPLE_TRACE_LEAVE ("No such file or directory"); +  return 0; +  } +  +  mapping(string:mixed) recurse (string path, Stat st) +  { +  // Note: Already got an extra TRACE_ENTER level on entry here. +     if (st->isdir) {    // RFC 2518 8.6.2    // The DELETE operation on a collection MUST act as if a
1185:    int fail;    if (!has_suffix(path, "/")) path += "/";    foreach(find_dir(path, id) || ({}), string fname) { -  mapping(string:mixed) sub_res = recurse(path+fname); +  fname = path + fname; +  if (Stat sub_stat = stat_file (fname, id)) { +  SIMPLE_TRACE_ENTER (this, "Deleting %O recursively", fname); +  mapping(string:mixed) sub_res = recurse(fname, sub_stat);    // RFC 2518 8.6.2    // 424 (Failed Dependancy) errors SHOULD NOT be in the    // 207 (Multi-Status).
1194:    // in the 207 (Multi-Status). The reason for this prohibition    // is that 204 (No Content) is the default success code.    if (sub_res && sub_res->error != 204 && sub_res->error != 424) { -  stat->add_status(path+fname, sub_res->error, sub_res->rettext); +  stat->add_status(fname, sub_res->error, sub_res->rettext);    if (sub_res->error >= 300) fail = 1;    }    } -  if (fail) return Roxen.http_status(424); +     } -  +  if (fail) { +  SIMPLE_TRACE_LEAVE ("Partial failure"); +  return Roxen.http_status(424); +  } +  } +  +  SIMPLE_TRACE_LEAVE (""); +  return 0;    };    -  return recurse (path) || delete_file(path, id) || Roxen.http_status(204); +  return recurse(path, st) || delete_file(path, id) || Roxen.http_status(204);   }      mapping(string:mixed) make_collection(string path, RequestID id)