# file-storage/www/download-archive/index.vuh ad_page_contract { @author yon@openforce.net @creation-date 2002-05-21 @version $Id: index.vuh,v 1.4 2002/08/06 13:27:15 yon Exp $ } -query { {object_id:integer,optional} } if {[exists_and_not_null object_id]} { set download_name [fs::get_file_system_safe_object_name -object_id $object_id] set ext [fs::get_archive_extension] if {![empty_string_p $ext]} { append download_name ".${ext}" } ad_returnredirect "${object_id}/${download_name}" ad_script_abort } # convenient way to get the values out of a list foreach {object_id download_name} [split [ad_conn path_info] /] {break} if {![fs::object_p -object_id $object_id]} { ad_return_complaint 1 "Object \#$object_id is not a file storage object." ad_script_abort } set user_id [ad_conn user_id] if {$user_id == 0} { set user_id "" } # publish the object to the file system set in_path [ns_tmpnam] file mkdir $in_path set file [fs::publish_object_to_file_system -object_id $object_id -path $in_path -user_id $user_id] set file_name [file tail $file] # create a temp dir to put the archive in set out_path [ns_tmpnam] file mkdir $out_path set out_file [file join ${out_path} ${download_name}] # get the archive command set cmd [fs::get_archive_command -in_file $file_name -out_file $out_file] # create the archive with_catch errmsg { exec bash -c "cd $in_path; $cmd; cd -" } { # some day we'll do something useful here error $errmsg } # return the archive to the connection. ns_returnfile 200 application/octet-stream $out_file # clean everything up file delete -force $in_path file delete -force $out_path