Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl,v diff -u -r1.34 -r1.35 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 10 Jan 2007 21:22:12 -0000 1.34 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 24 Dec 2008 00:20:46 -0000 1.35 @@ -149,9 +149,10 @@ } $apm_file file mkdir $dir - # cd, gunzip, and untar all in the same subprocess (to avoid having to - # chdir first). - exec sh -c "cd $dir ; [apm_gunzip_cmd] -q -c $apm_file | [apm_tar_cmd] xf -" 2>/dev/null + # avoid chdir + #ns_log notice "exec sh -c 'cd $dir ; [apm_gzip_cmd] -d -q -c $apm_file | [apm_tar_cmd] xf - 2>/dev/null'" + exec [apm_gzip_cmd] -d -q -c -S .apm $apm_file | [apm_tar_cmd] -xf - -C $dir 2> [apm_dev_null] + file delete $apm_file } @@ -182,7 +183,7 @@ # file; we need this to ensure that the tarballs are relative to the # package root directory ([acs_root_dir]/packages). - set cmd [list exec [apm_tar_cmd] cf - 2>/dev/null] + set cmd [list exec [apm_tar_cmd] cf - 2> [apm_dev_null]] foreach file $files { lappend cmd -C "[acs_root_dir]/packages" lappend cmd "$package_key/$file" @@ -455,14 +456,15 @@ } } -ad_proc -private apm_gunzip_cmd {} { +ad_proc -private apm_gzip_cmd {} { - @return A valid pointer to gunzip, 0 otherwise. + @return A valid pointer to gzip, 0 otherwise. } { - return gunzip + return gzip } + ad_proc -private apm_tar_cmd {} { @return A valid pointer to tar, 0 otherwise. @@ -472,14 +474,71 @@ } -ad_proc -private apm_gzip_cmd {} { - - @return A valid pointer to gzip, 0 otherwise. +ad_proc -private apm_dev_null {} { + @return null device + } { - return gzip + if {$::tcl_platform(platform) ne "windows"} { + return /dev/null + } else { + return nul + } } +ad_proc -private apm_transfer_file { + {-url} + {-output_file_name} +} { + # + # The original solution using ns_httpopen + file_copy does not work + # reliably under windows, for unknown reasons the downloaded file is + # truncated. + # + # Therefore, we check first if the optional xotcl-core components + # are available... + # + if {[info command ::xo::HttpRequest] ne ""} { + # + # ... use xo::HttpRequest... + # + #ns_log notice "Transfer $url based to $output_file_name on ::xo::HttpRequest" + # + set r [::xo::HttpRequest new -url $url] + set fileChan [open $output_file_name w 0640] + fconfigure $fileChan -translation binary -encoding binary + puts -nonewline $fileChan [$r set data] + close $fileChan + + } elseif {[set wget [::util::which wget]] ne ""} { + # + # ... if we have no ::xo::* and we have "wget" installed, we use + # it. + # + ns_log notice "Transfer $url based on wget" + catch {exec $wget -O $output_file_name $url} + + } else { + # + # Everything else failed, fall back to the original solution. + # + ns_log notice "Transfer $url based on ns_httpopen" + # Open a destination file. + set fileChan [open $output_file_name w 0640] + # Open the channel to the server. + set httpChan [lindex [ns_httpopen GET $url] 0] + ns_log Debug "APM: Copying data from $url" + fconfigure $httpChan -encoding binary + fconfigure $fileChan -encoding binary + # Copy the data + fcopy $httpChan $fileChan + # Clean up. + ns_log Debug "APM: Done copying data." + close $httpChan + close $fileChan + } +} + ad_proc -private apm_load_apm_file { {-callback apm_dummy_callback} {-url {}} @@ -496,23 +555,9 @@ } { # First download the apm file if a URL is provided if { $url ne "" } { + set file_path [ns_tmpnam].apm apm_callback_and_log $callback "
[ad_footer]" @@ -528,10 +573,11 @@ } } + #ns_log notice "*** try to exec [apm_gzip_cmd] -d -q -c -S .apm $file_path | [apm_tar_cmd] tf - 2> [apm_dev_null]" if { [catch { set files [split [string trim \ - [exec [apm_gunzip_cmd] -q -c $file_path | [apm_tar_cmd] tf - 2>/dev/null]] "\n"] - apm_callback_and_log $callback "[ad_quotehtml $errmsg]
[ad_quotehtml $errmsg]