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.3 -r1.4 --- openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 3 May 2001 04:00:49 -0000 1.3 +++ openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 6 May 2001 14:30:08 -0000 1.4 @@ -1,15 +1,28 @@ +ad_library { + + Functions that the content-repository uses to interact with the + file system. + + @author Dan Wickstrom (dcwickstrom@earthlink.net) + @creation-date Sat May 5 13:45 2001 + @cvs-id $Id$ +} + # The location for files -proc cr_fs_path {} { +ad_proc -public cr_fs_path {} { + + Root path of content repository files. + +} { return "[file dirname [string trimright [ns_info tcllib] "/"]]/content-repository-content-files" } -# This will generate the filename and set up the directory to it, too. -# This needs to scale to lots of files, and the location doesn't have to -# be meaningful. +ad_proc -private cr_create_content_file_path {item_id revision_id} { -# lifted from new-file-storage (DanW - OpenACS) + Creates a unique file in the content repository file system based off of + the item_id and revision_id of the content item. -proc cr_create_content_file { item_id revision_id client_filename } { +} { # Split out the version_id by groups of 2. set item_id_length [string length $item_id] @@ -38,7 +51,21 @@ append path "/" } - set content_file "${path}${revision_id}" + return "${path}${revision_id}" +} + +# lifted from new-file-storage (DanW - OpenACS) + +ad_proc -public cr_create_content_file {item_id revision_id client_filename} { + + Copies the file passed by client_filename to the content repository file + storage area, and it returns the relative file path from the root of the + content repository file storage area.. + +} { + + set content_file [cr_create_content_file_path $item_id $revision_id] + set ifp [open $client_filename r] set ofp [open [cr_fs_path]$content_file w] @@ -49,15 +76,27 @@ return $content_file } -proc cr_create_content_lob { lob_id client_filename } { +ad_proc -public cr_create_content_file_from_string {item_id revision_id str} { + 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. - db_transaction { +} { - db_with_handle db { - ns_pg blob_dml_file $db $lob_id $client_filename - } - } + set content_file [cr_create_content_file_path $item_id $revision_id] + set ofp [open [cr_fs_path]$content_file w] + ns_puts -nonewline $ofp $str + close $ofp - return 0 + return $content_file } + +ad_proc -public cr_file_size {relative_file_path} { + + Returns the size of a file stored in the content repository. Takes the + relative file path of the content repository file as an arguement. + +} { + return [file size [cr_fs_path]$relative_file_path] +} Index: openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/shared/Attic/portrait-bits-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql 3 May 2001 04:00:49 -0000 1.3 +++ openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql 6 May 2001 14:30:08 -0000 1.4 @@ -5,7 +5,7 @@ - select lob + select lob, storage_type from cr_revisions where revision_id = :revision_id Index: openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs-postgresql.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 4 May 2001 06:04:28 -0000 1.10 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 6 May 2001 14:30:08 -0000 1.11 @@ -375,40 +375,106 @@ set lob_sql [uplevel 2 [list db_bind_var_substitution $sql]] } - # get the content + # get the content - asssume it is in column 0, or optionally it can + # be returned as "content" with the storage type indicated by the + # "storage_type" column. + set selection [ns_db 1row $db $lob_sql] - set val [ns_set value $selection 0] + set content [ns_set value $selection 0] + for {set i 0} {$i < [ns_set size $selection]} {incr i} { + set name [ns_set key $selection $i] + if {[string equal $name storage_type]} { + set storage_type [ns_set value $selection $i] + } elseif {[string equal $name content]} { + set content [ns_set value $selection $i] + } + } + # this is an ugly hack, but it allows content to be written + # to a file/connection if it is stored as a lob or if it is + # stored in the content-repository as a file. (DanW - Openacs) + switch $type { blob_select_file { - if {[regexp {^[0-9]+$} $val match]} { - ns_pg blob_select_file $db $val $file - } elseif {[file exists $val]} { - set ifp [open $val r] + if {[info exists storage_type]} { + switch $storage_type { + file { + if {[file exists $content]} { + set ifp [open $content r] + set ofp [open $file w] + ns_cpfp $ifp $ofp + close $ifp + close $ofp + } else { + error "file: $content doesn't exist" + } + } + + lob { + if {[regexp {^[0-9]+$} $content match]} { + ns_pg blob_select_file $db $content $file + } else { + error "invalid lob_id: should be an integer" + } + } + + default { + error "invalid storage type" + } + } + } elseif {[file exists $content]} { + set ifp [open $content r] set ofp [open $file w] ns_cpfp $ifp $ofp close $ifp close $ofp + } elseif {[regexp {^[0-9]+$} $content match]} { + ns_pg blob_select_file $db $content $file } else { - error "lob id is not an integer" + error "invalid query" } } write_blob { - # this is an ugly hack, but it allows content to be written - # to the connection if it is stored as a lob or if it is - # stored in the content-repository as a file. (DanW - Openacs) - if {[file exists $val]} { - set ofp [open $val r] + if {[info exists storage_type]} { + switch $storage_type { + file { + if {[file exists $content]} { + set ofp [open $content r] + ns_writefp $ofp + close $ofp + } else { + error "file: $content doesn't exist" + } + } + + text { + ns_write $content + } + + lob { + if {[regexp {^[0-9]+$} $content match]} { + ns_pg blob_write $db $content + } else { + error "invalid lob_id: should be an integer" + } + } + + default { + error "invalid storage type" + } + } + } elseif {[file exists $content]} { + set ofp [open $content r] ns_writefp $ofp close $ofp - } elseif {[regexp {^[0-9]+$} $val match]} { - ns_pg blob_write $db $val + } elseif {[regexp {^[0-9]+$} $content match]} { + ns_pg blob_write $db $content } else { - error "file: $val doesn't exist" + ns_write $content } } } Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql 5 May 2001 17:39:19 -0000 1.9 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql 6 May 2001 14:30:08 -0000 1.10 @@ -74,7 +74,7 @@ update apm_package_versions - set content_length = [file size [cr_fs_path]$content_file] + set content_length = [cr_file_size $content_file] where version_id = :version_id @@ -83,7 +83,7 @@ - select '[cr_fs_path]' || content + select '[cr_fs_path]' || content as content, storage_type from cr_revisions where revision_id = (select content_item__get_latest_revision(item_id) from apm_package_versions