Branch: Tag:

1998-04-15

1998-04-15 21:28:49 by Henrik Grubbström (Grubba) <grubba@grubba.org>

PUT and DELETE now zap the entry in the stat_cache for the file.

Rev: server/modules/filesystems/filesystem.pike:1.31

8:   inherit "roxenlib";   inherit "socket";    - constant cvs_version= "$Id: filesystem.pike,v 1.30 1998/03/11 19:42:35 neotron Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.31 1998/04/15 21:28:49 grubba Exp $";   constant thread_safe=1;      
24:      // import Array;    + #define TRACE_ENTER(A,B) do{if(id->misc->trace_enter)id->misc->trace_enter((A),(B));}while(0) + #define TRACE_LEAVE(A) do{if(id->misc->trace_leave)id->misc->trace_leave((A));}while(0) +  +    int redirects, accesses, errors, dirlists;   int puts, deletes;   
288:      mixed find_file( string f, object id )   { +  TRACE_ENTER("find_file(\""+f+"\")", 0); +     object o;    int size;    string tmp;
306:    switch(-size)    {    case 1: +  case 3: +  case 4: +  TRACE_LEAVE("No file");    return 0; /* Is no-file */       case 2: -  +  TRACE_LEAVE("Is directory");    return -1; /* Is dir */       default:
318:    if(sizeof(id->not_query) < 2)    return 0;    redirects++; +  TRACE_LEAVE("Redirecting to \"" + +  id->not_query[..sizeof(id->not_query)-2] + +  "\"");    return http_redirect(id->not_query[..sizeof(id->not_query)-2], id);    }       if(!id->misc->internal_get && QUERY(.files)    && (tmp = (id->not_query/"/")[-1]) -  && tmp[0] == '.') +  && tmp[0] == '.') { +  TRACE_LEAVE("Is .-file");    return 0; -  +  }   #ifndef THREADS    object privs;    if (((int)id->misc->uid) && ((int)id->misc->gid) &&
335:    }   #endif    +  TRACE_ENTER("Opening file \"" + f + "\"", 0);    o = open( f, "r" );      #ifndef THREADS
345:    {    errors++;    report_error("Open of " + f + " failed. Permission denied.\n"); +  +  TRACE_LEAVE(""); +  TRACE_LEAVE("Permission denied.");    return http_low_answer(403, "<h2>File exists, but access forbidden "    "by user</h2>");    }       id->realfile = f; -  +  TRACE_LEAVE("");    accesses++;   #ifdef COMPAT -  if(QUERY(html)) /* Not very likely, really.. */ +  if(QUERY(html)) {/* Not very likely, really.. */ +  TRACE_LEAVE("Compat return");    return ([ "type":"text/html", "file":o, ]); -  +  }   #endif -  +  TRACE_LEAVE("Normal return");    return o;    }    break;
363:    if(!QUERY(put))    {    id->misc->error_code = 405; +  TRACE_LEAVE("PUT disallowed");    return 0;    }    -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) +  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  TRACE_LEAVE("PUT: Permission denied");    return http_auth_required("foo",    "<h1>Permission to 'PUT' files denied</h1>"); -  +  }    puts++;       object privs;
384:    privs = 0;    errors++;    report_error("Creation of " + f + " failed. Permission denied.\n"); +  TRACE_LEAVE("PUT: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }    -  +  TRACE_ENTER("PUT: Accepted", 0); +     rm( f );    mkdirhier( f ); -  +  +  /* Clear the stat-cache for this file */ +  if (stat_cache) { +  cache_set("stat_cache", f, 0); +  } +     object to = open(f, "wc");       privs = 0;
396:    if(!to)    {    id->misc->error_code = 403; +  TRACE_LEAVE("PUT: Open failed"); +  TRACE_LEAVE("Failure");    return 0;    }   
405:    putting[id->my_fd] -= strlen(id->data);    to->write( id->data );    } -  if(!putting[id->my_fd]) +  if(!putting[id->my_fd]) { +  TRACE_LEAVE("PUT: Just a string"); +  TRACE_LEAVE("Put: Success");    return http_string_answer("Ok"); -  +  }       if(id->clientprot == "HTTP/1.1") {    id->my_fd->write("HTTP/1.1 100 Continue\r\n");    }    id->my_fd->set_id( ({ to, id->my_fd }) );    id->my_fd->set_nonblocking(got_put_data, 0, done_with_put); -  +  TRACE_LEAVE("PUT: Pipe in progress"); +  TRACE_LEAVE("PUT: Success so far");    return http_pipe_in_progress();    break;   
420:    if(!QUERY(delete) || size==-1)    {    id->misc->error_code = 405; +  TRACE_LEAVE("DELETE: Disabled");    return 0;    } -  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) +  if(QUERY(check_auth) && (!id->auth || !id->auth[0])) { +  TRACE_LEAVE("DELETE: Permission denied");    return http_low_answer(403, "<h1>Permission to DELETE file denied</h1>"); -  +  }       if (QUERY(no_symlinks) && (contains_symlinks(path, oldf))) {    errors++;    report_error("Deletion of " + f + " failed. Permission denied.\n"); -  +  TRACE_LEAVE("DELETE: Contains symlinks");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }   
439:    privs=Privs("Deleting file", id->misc->uid, id->misc->gid );    }    +  /* Clear the stat-cache for this file */ +  if (stat_cache) { +  cache_set("stat_cache", f, 0); +  } +     if(!rm(f))    {    privs = 0;    id->misc->error_code = 405; -  +  TRACE_LEAVE("DELETE: Failed");    return 0;    }    privs = 0;    deletes++; -  +  TRACE_LEAVE("DELETE: Success");    return http_low_answer(200,(f+" DELETED from the server"));       default: -  +  TRACE_LEAVE("Not supported");    return 0;    }    report_error("Not reached..\n"); -  +  TRACE_LEAVE("Not reached");    return 0;   }