Roxen.git / server / modules / tags / writefile.pike

version» Context lines:

Roxen.git/server/modules/tags/writefile.pike:5:   //   // This module is open source software; you can redistribute it and/or   // modify it under the terms of the GNU General Public License as published   // by the Free Software Foundation; either version 2, or (at your option) any   // later version.   //      #define _ok id->misc->defines[" _ok"]      constant cvs_version = -  "$Id: writefile.pike,v 1.13 2003/01/26 02:25:25 mani Exp $"; +  "$Id: writefile.pike,v 1.14 2004/05/23 03:00:51 _cvs_stephen Exp $";   constant thread_safe = 1;      #include <module.h>   #include <config.h>      inherit "module";         // ---------------- Module registration stuff ----------------   
Roxen.git/server/modules/tags/writefile.pike:81:    inherit RXML.Frame;       array do_return(RequestID id) {    CACHE(0);    _ok = 1;    if(!sizeof(args->filename)) {    _ok = 0;    return 0;    }    -  string filename,rootpath,path,schroot=args->chroot||""; +  string real_filename,rootpath,path,schroot=args->chroot||"";    -  path = id->conf->real_file(id->not_query||"/", id); -  if (!path) -  parse_error ("There is no file system for %O that supports this tag " -  "(i.e. implements real_file).\n", id->not_query || "/"); -  +  path = id->not_query || "/";    path=dirname(path)+"/"; -  +     if (QUERY(onlysubdirs))    rootpath = path; -  else { -  rootpath = id->conf->real_file("/",id); -  if (!rootpath) -  parse_error ("There is no file system for / that supports this tag " -  "(i.e. implements real_file).\n"); +  else +  rootpath = "/"; +  +  string filename = +  Stdio.append_path(((schroot+args->filename)[0]=='/'? +  rootpath:path), +  Stdio.append_path(schroot, args->filename)); +  // Search for an existing real directory +  string d = dirname(filename); +  string real_dirname = id->conf->real_file(d+"/",id); +  string new_dir = ""; +  while (!real_dirname && sizeof(d)) { +  new_dir = Stdio.append_path(basename(d), new_dir); +  d = dirname(d); +  if (d == "/") d = ""; +  real_dirname = id->conf->real_file(d+"/",id);    } -  +  if (!real_dirname) +  parse_error ("There is no file system for %O that supports this tag " +  "(i.e. implements real_file).\n", dirname(filename));    -  filename=((schroot+args->filename)[0]=='/'?rootpath:path)+ -  Stdio.append_path(schroot, args->filename); +  real_filename = Stdio.append_path(real_dirname, new_dir, +  basename(filename)); +     if(args->remove) { -  if(!rm(filename)) +  if(!rm(real_filename))    _ok = 0; -  } else if(IS(args->moveto)) { -  if(!mv(filename,((schroot+args->moveto)[0]=='/'?rootpath:path)+ -  Stdio.append_path(schroot, args->moveto))) +  } +  else +  if(IS(args->moveto)) { +  string filename = +  Stdio.append_path(((schroot+args->moveto)[0]=='/'? +  rootpath:path), +  Stdio.append_path(schroot, args->moveto)); +  string real_dirname = id->conf->real_file(dirname(filename)+"/",id); +  if (!real_dirname) +  parse_error ("There is no file system for %O that supports this " +  "tag (i.e. implements real_file).\n", +  dirname(filename)); +  string real_moveto = +  Stdio.append_path(real_dirname, basename(filename)); +  +  if(!mv(real_filename, real_moveto))    _ok = 0; -  } else { +  } +  else {    string towrite;    if(args->from) {    towrite=RXML.user_get_var(args->from, "form");    if(!towrite ||    IS(args["max-size"]) && sizeof(towrite)>(int)args["max-size"]) {    _ok = 0;    return 0;    } -  } else -  towrite=content; +  } +  else +  towrite=content||"";    object privs;    ;{ Stat st;    string diro,dirn;    int domkdir=0; -  for(dirn=filename; +  for(dirn=real_filename;    diro=dirn, diro!=(dirn=dirname(dirn)) && !(st = file_stat(dirn));    domkdir=1);    if(st) {    privs = Privs("Writefile", st->uid, st->gid);    if(domkdir && args->mkdirhier) -  Stdio.mkdirhier(dirname(filename)); +  Stdio.mkdirhier(dirname(real_filename));    }    }    _ok = 0;    object file=Stdio.File(); -  if(file->open(lastfile=filename, args->append?"wrca":"wrct")) { +  if(file->open(lastfile=real_filename, args->append?"wrca":"wrct")) {    _ok = 1; -  +  if(String.width(towrite)>8) +  towrite = string_to_utf8(towrite);    file->write(towrite);    object dims;    if (IS(args["min-height"])|| IS(args["max-height"])||    IS(args["min-width"]) || IS(args["max-width"])) {    file->seek(0);    dims = Dims.dims();    array xy = dims->get(file);    if(xy &&    (IS(args["min-height"])&& xy[1] < (int)args["min-height"]||    IS(args["max-height"])&& xy[1] > (int)args["max-height"]||