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.16.2.3 -r1.16.2.4 --- openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 3 Jul 2020 07:27:29 -0000 1.16.2.3 +++ openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 22 Feb 2021 11:47:19 -0000 1.16.2.4 @@ -77,13 +77,7 @@ file copy -force -- $client_filename $dir$content_file } - # 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 - } + cr_add_to_file_creation_log $content_file return $content_file } @@ -93,17 +87,15 @@ 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 [cr_fs_path]/file-creation.log a] - puts $f $content_file - close $f } + cr_add_to_file_creation_log $content_file return $content_file } @@ -123,15 +115,18 @@ # involving file inserts in the content repository. # -ad_proc -public cr_cleanup_orphaned_files {} { +ad_proc -private cr_add_to_file_creation_log {content_file} { - Helper proc to cleanup orphaned files in the content - repository. Orphaned files can be created during aborted - transactions involving the files being added to the content - repository. + Record an entry in the file creation log for managing orphaned + files. } { - cr_delete_orphans [cr_get_file_creation_log] + set dir [cr_fs_path] + ad_mutex_eval [nsv_get mutex cr_file_creation] { + set f [open $dir/file-creation.log a] + puts $f $content_file + close $f + } } ad_proc -private cr_get_file_creation_log {} { @@ -156,19 +151,38 @@ return $content } -ad_proc -public cr_count_file_entries {name} { +ad_proc -private cr_check_file_entry {name} { - Count the number of entries from the content repository having the - specified partial path their content field. The result should be - 0 or 1 in consistent databases. + Check if an entriy from the content repository having the + specified partial path their content field exists. + @result boolean success + } { - db_string count_entries {} + db_0or1orw check_entry { + SELECT 1 FROM cr_revisions + WHERE substring(content, 1, 100) = substring(:name, 1, 100) + } } +ad_proc -private cr_count_file_entries {name} { + + Count entries an entries from the content repository having the + specified partial path their content field. + + @result integer count + +} { + db_string count_entries { + SELECT count(*) FROM cr_revisions + WHERE substring(content, 1, 100) = substring(:name, 1, 100) + } +} + + ad_proc -private cr_delete_orphans {files} { - delete orphaned files in the content repository + Delete orphaned files in the content repository. } { set dir [cr_fs_path]