--- parser3/src/classes/file.C 2001/07/18 16:11:11 1.41 +++ parser3/src/classes/file.C 2001/07/24 09:45:27 1.45 @@ -5,9 +5,9 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: file.C,v 1.41 2001/07/18 16:11:11 parser Exp $ + $Id: file.C,v 1.45 2001/07/24 09:45:27 parser Exp $ */ -static const char *RCSId="$Id: file.C,v 1.41 2001/07/18 16:11:11 parser Exp $"; +static const char *RCSId="$Id: file.C,v 1.45 2001/07/24 09:45:27 parser Exp $"; #include "classes.h" #include "pa_request.h" @@ -59,6 +59,17 @@ static void _delete(Request& r, const St file_delete(pool, r.absolute(vfile_name.as_string())); } +static void _move(Request& r, const String&, MethodParams *params) { + Pool& pool=r.pool(); + Value& vfrom_file_name=params->as_no_junction(0, "from file name must not be code"); + Value& vto_file_name=params->as_no_junction(1, "to file name must not be code"); + + // unlink + file_move(pool, + r.absolute(vfrom_file_name.as_string()), + r.absolute(vto_file_name.as_string())); +} + static void _find(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Value& vfile_name=params->as_no_junction(0, "file name must not be code"); @@ -210,7 +221,7 @@ static void _exec_cgi(Request& r, const //out.APPEND_CONST("content-type:text/plain\nheader:test-header\n\ntest-body"); //out<(r.self); @@ -229,7 +240,7 @@ static void _exec_cgi(Request& r, const PTHROW(0, 0, &method_name, "output does not contain CGI header; exit code=%d; size=%u; text: \"%s\"", - exit_code, (uint)out.size(), out.cstr()); + status, (uint)out.size(), out.cstr()); } const String& header=out.mid(0, pos); @@ -245,10 +256,10 @@ static void _exec_cgi(Request& r, const // body self.set(false/*not tainted*/, body->cstr(String::UL_AS_IS), body->size()); - // $exit-code + // $status self.fields().put( - *new(pool) String(pool, "exit-code"), - new(pool) VInt(pool, exit_code)); + *new(pool) String(pool, "status"), + new(pool) VInt(pool, status)); // $stderr if(err.size()) { @@ -256,7 +267,7 @@ static void _exec_cgi(Request& r, const *new(pool) String(pool, "stderr"), new(pool) VString(err)); - SAPI::log(pool, "file:cgi: %s", err.cstr()); + SAPI::log(pool, "file:%s: %s", cgi?"cgi":"exec", err.cstr()); } } static void _exec(Request& r, const String& method_name, MethodParams *params) { @@ -279,6 +290,9 @@ MFile::MFile(Pool& apool) : Methoded(apo // ^delete[file-name] add_native_method("delete", Method::CT_STATIC, _delete, 1, 1); + // ^move[from-file-name;to-file-name] + add_native_method("move", Method::CT_STATIC, _move, 2, 2); + // ^find[file-name] // ^find[file-name]{when-not-found} add_native_method("find", Method::CT_STATIC, _find, 1, 2);