Index: openacs-4/packages/acs-content-repository/tcl/acs-content-repository-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/acs-content-repository-procs.tcl,v diff -u -N -r1.7 -r1.7.2.1 --- openacs-4/packages/acs-content-repository/tcl/acs-content-repository-procs.tcl 30 Mar 2013 19:07:23 -0000 1.7 +++ openacs-4/packages/acs-content-repository/tcl/acs-content-repository-procs.tcl 25 Dec 2013 12:40:13 -0000 1.7.2.1 @@ -67,3 +67,43 @@ } } } + +## +## Check for orphans in the content respository directory, and delete +## such files if required. +## +## gustaf.neumann@wu-wien.ac.at +## + + +ad_proc cr_check_orphaned_files {-delete:boolean} { + + Check for orphaned files in the content respository directory, and + delete such files if required. Orphaned files might be created, when + files add added to the content repository, but the transaction is being aborted. + + @param -delete delete the orphaned files + +} { + package require fileutil + + set cr_root [nsv_get CR_LOCATIONS CR_FILES] + set root_length [string length $cr_root] + set result "" + + # For every file in the content respository directory, check if this + # file is still referenced from the content-revisions. + + foreach f [::fileutil::find $cr_root "file isfile"] { + set name [string range $f $root_length end] + if {![regexp {^[0-9/]+$} $name]} continue + set x [db_string _ {select count(*) from cr_revisions where content = :name}] + if {$x > 0} continue + + lappend result $f + if {$delete_p} { + file delete $f + } + } + return $result +}