content::revision::check_dirs (private)

 content::revision::check_dirs [ -max_results max_results ] \
    [ -max_checks max_checks ] [ -returnlist ] [ -prune ]

Defined in packages/acs-content-repository/tcl/content-revision-procs.tcl

Figure out, how many directories in the CR are empty, report them optionally or delete them optionally.

Switches:
-max_results (optional, defaults to "5000")
stop after having found so many empty directories
-max_checks (optional, defaults to "10000")
stop after having checked so many directories
-returnlist (optional, boolean)
return the directories as part of the result
-prune (optional, boolean)
delete the found empty directories
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
%3 cr_fs_path cr_fs_path (private) content::revision::check_dirs content::revision::check_dirs content::revision::check_dirs->cr_fs_path

Testcases:
No testcase defined.
Source code:
    set paths [cr_fs_path CR_FILES]
    set prefix_length [string length $paths]
    set count 1
    set empty_dirs 0
    set dirs 0
    set empty_dir_list {}
    while {[llength $paths] > 0} {
        # get the first path
        set paths [lassign $paths path]
        #ns_log notice "popping path '$path' form paths, remaining [llength $paths]"

        set children [glob -nocomplain -directory $path *]
        set nr_children 0
        incr dirs
        foreach child $children {
            if {[file tail $child] in {. ..}} {
                continue
            }
            if {[file isdirectory $child]} {
                #
                # Using "lappend" leads to a breadth-search: might be
                # slow when the directories a huge, since it takes a
                # while until leaves are found.
                #
                #lappend paths $child

                set paths [lreplace $paths -1 -2 $child]
                #ns_log notice "child is dir $child"
            }
            incr nr_children
        }
        if {$nr_children == 0} {
            incr empty_dirs
            ns_log notice "check_dirs: directory $path is empty ($empty_dirs out of $dirs)"
            lappend empty_dir_list $path
            if {$prune_p && [regexp {^\d+$} [file tail $path]]} {
                file delete $path
            }
        }
        if {$empty_dirs >= $max_results || $dirs >= $max_checks} {
            break
        }
    }
    set msg "$empty_dirs out of $dirs directories are empty"
    ns_log notice "check_dirs: $msg"
    if {$returnlist_p} {
        append msg \n [join $empty_dir_list \n]
    }
    return $msg
Generic XQL file:
packages/acs-content-repository/tcl/content-revision-procs.xql

PostgreSQL XQL file:
packages/acs-content-repository/tcl/content-revision-procs-postgresql.xql

Oracle XQL file:
packages/acs-content-repository/tcl/content-revision-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: