Commit f1af04a6 authored by Frank Bergmann's avatar Frank Bergmann

- Updated intranet-filestorage

  replacing exec by im_exec and doing
  some testing on Linux
parent f903548e
......@@ -70,7 +70,13 @@ ad_proc -public im_filestorage_find_cmd {} {
Returns the Unix/Linux/Windows find command as specified in the
intranet-core.FindCmd command
} {
return [util_memoize im_filestorage_find_cmd_helper 3600]
}
ad_proc -public im_filestorage_find_cmd_helper {} {
Returns the Unix/Linux/Windows find command as specified in the
intranet-core.FindCmd command
} {
# -------------------------------------------------
# First check for a default value for each platform:
global tcl_platform
......@@ -92,7 +98,7 @@ ad_proc -public im_filestorage_find_cmd {} {
# Just run find on itself - this should return exactly one file
set winaoldir $::env(AOLDIR)
set unixaoldir [string map {\\ /} ${winaoldir}]
set file_list [exec $find_cmd ${unixaoldir}/bin/${find_cmd}.exe -maxdepth 0]
set file_list [im_exec $find_cmd ${unixaoldir}/bin/${find_cmd}.exe -maxdepth 0]
} err_msg]} {
return $find_cmd
}
......@@ -106,7 +112,7 @@ ad_proc -public im_filestorage_find_cmd {} {
if { ![catch {
# Just run find on itself - this should return exactly one file
set file_list [exec $find_cmd $find_cmd -maxdepth 0]
set file_list [im_exec $find_cmd $find_cmd -maxdepth 0]
} err_msg]} {
return $find_cmd
}
......@@ -119,7 +125,7 @@ ad_proc -public im_filestorage_find_cmd {} {
if { [catch {
# Just run find on itself - this should return exactly one file
set file_list [exec $find_cmd $find_cmd -maxdepth 0]
set file_list [im_exec $find_cmd $find_cmd -maxdepth 0]
} err_msg]} {
ad_return_complaint 1 "<B>Configuration Error</b>:
......@@ -300,8 +306,6 @@ proc intranet_download { folder_type } {
}
ad_proc -public im_package_filestorage_id { } {
} {
return [util_memoize im_package_filestorage_id_helper]
......@@ -356,17 +360,17 @@ ad_proc -public im_filestorage_find_files { project_id } {
} {
set project_path [im_filestorage_project_path $project_id]
set find_cmd [im_filestorage_find_cmd]
if { [catch {
ns_log Notice "im_filestorage_find_files: Checking $project_path"
exec /bin/mkdir -p $project_path
exec /bin/chmod ug+w $project_path
set file_list [exec $find_cmd $project_path -noleaf -type f]
file mkdir $project_path
im_exec chmod ug+w $project_path
set file_list [im_exec $find_cmd $project_path -noleaf -type f]
} err_msg] } {
# Probably some permission errors - return empty string
set err "'exec $find_cmd $project_path -noleaf -type f' failed with error:
err_msg=$err_msg\n"
ns_log Error "im_filestorage_find_files: 'file mkdir $project_path; chmod ug+w $project_path; $find_cmd $project_path -noleaf -type f' failed with error: err_msg=$err_msg\n"
set file_list ""
}
......@@ -1000,10 +1004,8 @@ ad_proc im_filestorage_copy_source_directory { project_id sub_project_id } {
if {"" != $source_language} {
ns_log Notice "im_filestorage_copy_directory: $source_dir -> $sub_source_dir"
if {[catch {
ns_log Notice "im_filestorage_copy_source_directory: exec /bin/cp -r $source_dir/* $sub_source_dir/"
exec /bin/cp -r "$source_dir" "$sub_source_dir"
ns_log Notice "im_filestorage_copy_source_directory: im_exec cp -r $source_dir/* $sub_source_dir/"
im_exec cp -r "$source_dir" "$sub_source_dir"
} err_msg]} { return $err_msg }
}
......@@ -1063,10 +1065,9 @@ where
ns_log Notice "im_filestorage_create_directories: company_dir=$company_dir"
if { [catch {
if {![file exists $company_dir]} {
ns_log Notice "exec /bin/mkdir -p $company_dir"
exec /bin/mkdir -p $company_dir
ns_log Notice "exec /bin/chmod ug+w $company_dir"
exec /bin/chmod ug+w $company_dir
file mkdir $company_dir
ns_log Notice "im_exec chmod ug+w $company_dir"
im_exec chmod ug+w $company_dir
}
} err_msg] } { return $err_msg }
......@@ -1075,10 +1076,9 @@ where
ns_log Notice "im_filestorage_create_directories: project_dir=$project_dir"
if { [catch {
if {![file exists $project_dir]} {
ns_log Notice "exec /bin/mkdir -p $project_dir"
exec /bin/mkdir -p $project_dir
ns_log Notice "exec /bin/chmod ug+w $project_dir"
exec /bin/chmod ug+w $project_dir
file mkdir $project_dir
ns_log Notice "im_exec chmod ug+w $project_dir"
im_exec chmod ug+w $project_dir
}
} err_msg]} { return $err_msg }
......@@ -1088,10 +1088,9 @@ where
ns_log Notice "im_filestorage_create_directories: source_dir=$source_dir"
if {[catch {
if {![file exists $source_dir]} {
ns_log Notice "exec /bin/mkdir -p $source_dir"
exec /bin/mkdir -p $source_dir
ns_log Notice "exec /bin/chmod ug+w $source_dir"
exec /bin/chmod ug+w $source_dir
file mkdir $source_dir
ns_log Notice "im_exec chmod ug+w $source_dir"
im_exec chmod ug+w $source_dir
}
} err_msg]} {
return $err_msg
......@@ -1104,10 +1103,9 @@ where
ns_log Notice "im_filestorage_create_directories: source_dir=$source_dir"
if {[catch {
if {![file exists $source_dir]} {
ns_log Notice "exec /bin/mkdir -p $source_dir"
exec /bin/mkdir -p $source_dir
ns_log Notice "exec /bin/chmod ug+w $source_dir"
exec /bin/chmod ug+w $source_dir
file mkdir $source_dir
ns_log Notice "im_exec chmod ug+w $source_dir"
im_exec chmod ug+w $source_dir
}
} err_msg]} { return $err_msg }
}
......@@ -1128,10 +1126,9 @@ where
ns_log Notice "im_filestorage_create_directories: dir=$dir"
if {![file exists $dir]} {
if {[catch {
ns_log Notice "exec /bin/mkdir -p $dir"
exec /bin/mkdir -p $dir
ns_log Notice "exec /bin/chmod ug+w $dir"
exec /bin/chmod ug+w $dir
file mkdir $dir
ns_log Notice "im_exec chmod ug+w $dir"
im_exec chmod ug+w $dir
} err_msg]
} { return $err_msg }
}
......@@ -1615,9 +1612,9 @@ ad_proc -public im_filestorage_base_component { user_id object_id object_name ba
if { [catch {
# Executing the find command
exec /bin/mkdir -p $find_path
exec /bin/chmod ug+w $find_path
set file_list [exec $find_cmd $find_path -noleaf]
file mkdir $find_path
im_exec chmod ug+w $find_path
set file_list [im_exec $find_cmd $find_path -noleaf]
set files [lsort [split $file_list "\n"]]
} err_msg] } {
......@@ -2157,14 +2154,6 @@ ad_proc im_filestorage_file_type_icon {ext} {
}
ad_proc im_filestorage_create_folder {folder folder_name} {
Create a new folder
} {
if { [catch {
exec mkdir $folder/$folder_name
} err_msg] } { return $err_msg }
}
ad_proc im_filestorage_is_directory_empty {folder} {
} {
......@@ -2205,14 +2194,6 @@ ad_proc im_filestorage_delete_folder {project_id folder_id folder} {
} err_msg] } { return $err_msg }
}
ad_proc im_filestorage_erase_files { project_id file_name } {
} {
if { [catch {
exec rm $file_name
} err_msg] } { return $err_msg }
}
# -------------------------------------------------------
......
......@@ -350,21 +350,20 @@ switch $actions {
# Get folders with read permission
set dest_path {}
set folder_sql "
select
f.path as folder_path
from
im_fs_folder_perms p,
select f.path as folder_path
from im_fs_folder_perms p,
im_fs_folders f
where
f.object_id = :object_id
where f.object_id = :object_id
and p.folder_id = f.folder_id
and p.profile_id in ([join $user_memberships ", "])
and p.read_p = '1'
"
db_foreach get_folders $folder_sql {
lappend dest_path "$base_path/$folder_path"
set path "$base_path/$folder_path"
if {![file readable $path]} { continue }
lappend dest_path $path
}
# Permissions for all usual projects, companies etc.
set object_type [db_string acs_object_type "select object_type from acs_objects where object_id=:object_id"]
set perm_cmd "${object_type}_permissions \$user_id \$object_id object_view object_read object_write object_admin"
......@@ -407,7 +406,6 @@ switch $actions {
ad_script_abort
}
# Determine a random .tgz zip_file
set r [ns_rand 10000000]
set zip_file "zip.$user_id.$r.tgz"
......@@ -417,17 +415,18 @@ switch $actions {
set tmp_path [im_filestorage_tmp_path]
set zip_file_path "$tmp_path/$zip_file"
# build exec command
set tar_command "/bin/tar czf $zip_file_path"
# build im_exec command
set tar_command [list im_exec tar czf $zip_file_path -P]
foreach path $dest_path {
lappend tar_command $path
}
if { [catch {
ns_log Notice "intranet-filestorage/action: zip: About to execute tar_command=$tar_command"
eval "exec [join $tar_command]"
eval $tar_command
} err_msg] } {
ns_log Error "------> $err_msg"
ns_log Error "intranet-filestorage/action: Error executing '$tar_command': $err_msg"
ad_return_complaint 1 "intranet-filestorage/action: <br>Error executing '$tar_command': $err_msg"
# Nothing. We check if TAR was successfull if the file exists.
}
......@@ -577,6 +576,7 @@ switch $actions {
ad_returnredirect "$url_base?[export_url_bind_vars $bind_vars]"
}
"del" {
# --------------------- Delete ---------------------
......@@ -686,10 +686,5 @@ foreach var [ad_ns_set_keys $bind_vars] {
}
append vars "url_base=$url_base\n"
db_release_unused_handles
ad_return_complaint 1 "<pre>$vars</pre>"
return
set page_title "[_ intranet-filestorage.lt_Upload_into_my_folder]"
......@@ -51,9 +51,8 @@ append base_path $bread_crum_path
set char_style [parameter::get -package_id [im_package_filestorage_id] -parameter "FilenameCharactersSupported" -default "none"]
set folder_name [im_l10n_normalize_string -style $char_style $folder_name]
set err_msg [im_filestorage_create_folder $base_path $folder_name]
file mkdir "$base_path/$folder_name"
db_release_unused_handles
ad_returnredirect $return_url
......
......@@ -73,7 +73,7 @@ foreach id [array names file_id] {
return
}
set erase [im_filestorage_erase_files $object_id $base_path/$id_path($id)]
im_exec rm "$base_path/$id_path($id)"
}
......
......@@ -148,10 +148,9 @@ set dest_path "$base_path/$bread_crum_path/$client_filename"
ns_log Notice "dest_path=$dest_path"
if { [catch {
ns_log Notice "/bin/mv $tmp_filename $dest_path"
exec /bin/cp $tmp_filename $dest_path
ns_log Notice "/bin/chmod ug+w $dest_path"
exec /bin/chmod ug+w $dest_path
file copy -force -- $tmp_filename $dest_path
ns_log Notice "chmod ug+w $dest_path"
im_exec chmod ug+w $dest_path
} err_msg] } {
# Probably some permission errors
ad_return_complaint "Error writing upload file" $err_msg
......
......@@ -131,12 +131,11 @@ set dest_path "$base_path/$bread_crum_path"
ns_log Notice "upload-zip-2: dest_path=$dest_path"
ns_log Notice "upload-zip-2: tmp_filename=$tmp_filename"
if { [catch {
ns_log Notice {upload-zip-2: /bin/bash -c "cd $dest_path; unzip -oL $tmp_filename"}
set unzip_result [exec /bin/bash -c "cd $dest_path; unzip -oL $tmp_filename"]
ns_log Notice "upload-zip-2: /bin/chmod ug+w $dest_path"
exec /bin/chmod ug+w $dest_path
ns_log Notice "upload-zip-2: bash -c 'cd $dest_path; unzip -oL $tmp_filename'"
set unzip_result [im_exec bash -c "cd $dest_path; unzip -oL $tmp_filename"]
ns_log Notice "upload-zip-2: chmod ug+w $dest_path"
im_exec chmod ug+w $dest_path
} err_msg] } {
# Probably some permission errors
ad_return_complaint 1 "Error writing upload file:<br><pre>$err_msg</pre>"
......
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