Changeset 24427


Ignore:
Timestamp:
Apr 24, 2007, 8:14:22 AM (10 years ago)
Author:
eridius@…
Message:

Add test for deleting files during traversal

Location:
trunk/base/src/pextlib1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/pextlib1.0/fs-traverse.c

    r24423 r24427  
    5959#include <tcl.h>
    6060
    61 static int do_traverse(Tcl_Interp *interp, int flags, char * CONST *targets, char *varname, Tcl_Obj *body);
     61static int do_traverse(Tcl_Interp *interp, int flags, char * CONST *targets, Tcl_Obj *varname, Tcl_Obj *body);
    6262
    6363#define F_DEPTH 0x1
     
    6868FsTraverseCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
    6969{
    70     char *varname;
     70    Tcl_Obj *varname;
    7171    Tcl_Obj *body;
    7272    int flags = 0;
     
    101101    }
    102102   
    103     varname = Tcl_GetString(*objv);
     103    varname = *objv;
    104104    ++objv, --objc;
    105105   
     
    123123
    124124static int
    125 do_traverse(Tcl_Interp *interp, int flags, char * CONST *targets, char *varname, Tcl_Obj *body)
     125do_traverse(Tcl_Interp *interp, int flags, char * CONST *targets, Tcl_Obj *varname, Tcl_Obj *body)
    126126{
    127127    int rval = TCL_OK;
     
    137137            {
    138138                if (!(flags & F_DEPTH) != !(ent->fts_info == FTS_D)) {
    139                     Tcl_SetVar(interp, varname, ent->fts_path, 0);
     139                    Tcl_Obj *path = Tcl_NewStringObj(ent->fts_path, ent->fts_pathlen);
     140                    Tcl_ObjSetVar2(interp, varname, NULL, path, 0);
    140141                    if ((rval = Tcl_EvalObjEx(interp, body, 0)) == TCL_CONTINUE) {
    141142                        fts_set(root_fts, ent, FTS_SKIP);
  • trunk/base/src/pextlib1.0/tests/fs-traverse.tcl

    r24422 r24427  
    7979        set output [list]
    8080        fs-traverse file $root {
    81             lappend output $file
    8281            if {[string match */a $file]} {
    8382                continue
    8483            }
     84            lappend output $file
    8585        }
    8686        check_output $output $trees(5)
     
    9494            }
    9595        }
     96       
     97        # NOTE: This should be the last test performed, as it modifies the file tree
     98        # Test to make sure deleting files during traversal works as expected
     99        set output [list]
     100        fs-traverse file $root {
     101            if {[string match */a $file]} {
     102                # use /bin/rm because on 10.3 file delete doesn't work on directories properly
     103                exec /bin/rm -rf $file
     104                continue
     105            }
     106            lappend output $file
     107        }
     108        check_output $output $trees(5)
    96109    } errMsg]
    97110    set savedInfo $errorInfo
     
    270283    set trees(5) "
    271284        $root           directory
    272         $root/a         directory
    273         $root/b         directory
    274         $root/b/a       directory
    275         $root/b/b       directory
    276         $root/b/c       directory
    277         $root/b/c/a     file
     285        $root/b         directory
     286        $root/b/b       directory
     287        $root/b/c       directory
    278288        $root/b/c/b     file
    279289        $root/b/c/c     file
Note: See TracChangeset for help on using the changeset viewer.