Commit 0145b60a authored by salo's avatar salo

fix sha1 calculation

parent 7963279e
......@@ -55,6 +55,8 @@ set folder_path ""
# Main hierarchical SQL
#
set top_level [db_string top_level "select tree_level(tree_sortkey) from cr_items where item_id = :folder_id"]
set sql "
......@@ -63,7 +65,7 @@ set sql "
ci.name as file_name,
cr.revision_id as version_id,
tree_level(ci.tree_sortkey) - :top_level as level,
encode(digest(cr.content, 'sha1'), 'hex') as sha1,
-- encode(digest(cr.content, 'sha1'), 'hex') as sha1,
(select count(*) from cr_items child where child.parent_id = ci.item_id) as num_children,
ci.*,
cr.*,
......@@ -110,6 +112,10 @@ db_multirow file_multirow file_list $sql {
set valid_vars [list level version_id type publish_date mime_type content_length sha1 title description]
set valid_vars [lsort -unique $valid_vars]
# needed to calculate sha1
set storage_area_key "CR_FILES"
set storage_area_path [cr_fs_path $storage_area_key]
ns_log Debug "file-tree.json.tcl: storage_area_key($storage_area_key) storage_area_path($storage_area_path)"
set file_json ""
set ctr 0
......@@ -117,7 +123,7 @@ set old_level 0
set indent ""
template::multirow foreach file_multirow {
ns_log Notice "file-tree.json.tcl: file_id=$file_id, file_id=$file_id"
ns_log Notice "file-tree.json.tcl: file_id=$file_id, file_id=$file_id, version_id=$version_id, name($file_name)"
if {$debug_p} { append file_json "\n// finish: ctr=$ctr, level=$level, old_level=$old_level\n" }
# -----------------------------------------
......@@ -168,6 +174,15 @@ ${indent}\t\"expanded\":$expanded,
append file_json "${indent}\t\"children\":\[\],\n"
}
# version_id is empty for directories
if {"" eq $version_id} {
set sha1 ""
} else {
set filename [db_string filename "select :storage_area_path || content from cr_revisions where revision_id = :version_id"]
set sha1 [string range [exec /usr/bin/sha1sum "$filename"] 0 39]
ns_log Debug "file-tree.json.tcl: version_id($version_id) filename($filename) sha1($sha1)"
}
foreach var $valid_vars {
# Skip xml_* variables (only used by MS-File)
if {[regexp {^xml_} $var match]} { continue }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment