Index: openacs-4/packages/acs-content-repository/tcl/content-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-procs.tcl,v diff -u -r1.12.2.1 -r1.12.2.2 --- openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 31 Dec 2013 16:21:12 -0000 1.12.2.1 +++ openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 18 Jan 2014 11:36:44 -0000 1.12.2.2 @@ -29,22 +29,22 @@ set path "/" for {set i 0} {$i < $item_id_length} {incr i} { - append path [string range $item_id $i $i] - if {($i % 2) == 1} { - if {$i < $item_id_length} { - # Check that the directory exists - if {![file exists [cr_fs_path]$path]} { - file mkdir [cr_fs_path]$path - } - - append path "/" - } - } + append path [string range $item_id $i $i] + if {($i % 2) == 1} { + if {$i < $item_id_length} { + # Check that the directory exists + if {![file exists [cr_fs_path]$path]} { + file mkdir [cr_fs_path]$path + } + + append path "/" + } + } } # Check that the directory exists if {![file exists [cr_fs_path]$path]} { - file mkdir [cr_fs_path]$path + file mkdir [cr_fs_path]$path } if {[string index $path end] ne "/" } { @@ -80,9 +80,9 @@ # Record an entry in the file creation log for managing orphaned # files. ad_mutex_eval [nsv_get mutex cr_file_creation] { - set f [open $dir/file-creation.log a] - puts $f $content_file - close $f + set f [open $dir/file-creation.log a] + puts $f $content_file + close $f } return $content_file @@ -93,18 +93,17 @@ Copies the string to the content repository file storage area, and it returns the relative file path from the root of the content repository file storage area. - } { + ad_mutex_eval [nsv_get mutex cr_file_creation] { - set content_file [cr_create_content_file_path $item_id $revision_id] - set ofp [open [cr_fs_path]$content_file w] - puts -nonewline $ofp $str - close $ofp + set f [open $dir/file-creation.log a] + puts $f $content_file + close $f - ad_mutex_eval [nsv_get mutex cr_file_creation] { - set f [open $dir/file-creation.log a] - puts $f $content_file - close $f + set content_file [cr_create_content_file_path $item_id $revision_id] + set ofp [open [cr_fs_path]$content_file w] + puts -nonewline $ofp $str + close $ofp } return $content_file @@ -145,11 +144,11 @@ } { set dir [cr_fs_path] ad_mutex_eval [nsv_get mutex cr_file_creation] { - set f [open $dir/file-creation.log] - set content [read $f] - close $f - # truncate the log file - set f [open $dir/file-creation.log w]; close $f + set f [open $dir/file-creation.log] + set content [read $f] + close $f + # truncate the log file + set f [open $dir/file-creation.log w]; close $f } return $content } @@ -171,16 +170,29 @@ } { set dir [cr_fs_path] foreach name $files { - if {![file exists $dir$name]} { - # the file does not exist anymore, nothing to do - continue - } - set count [cr_count_file_entries $name] - if {$count == 0} { - # the content entry does not exist anymore, therefore the - # file is an orphan and should be removed - ns_log notice "delete orphaned file $dir$name" - file delete $dir$name - } + + if {![file exists $dir$name]} { + # the file does not exist anymore, nothing to do + continue + } + + if {![regexp {^[0-9/]+$} $name]} { + ns_log notice "orphan handling: ignore strange entry from deletion log <$dir$name>" + } + + set count [cr_count_file_entries $name] + if {$count == 0} { + # the content entry does not exist anymore, therefore the + # file is an orphan and should be removed + ns_log notice "delete orphaned file $dir$name" + file delete $dir$name + } } } + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: