Index: openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl,v diff -u -r1.56 -r1.57 --- openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl 30 Sep 2003 16:29:51 -0000 1.56 +++ openacs-4/packages/acs-tcl/tcl/apm-install-procs.tcl 2 Oct 2003 14:32:22 -0000 1.57 @@ -421,10 +421,11 @@ if { [string match "[apm_workspace_install_dir]*" $package_path] } { # Package is being installed from the apm_workspace dir (expanded from .apm file) + + # Backup any existing (old) package in packages dir first set old_package_path [acs_package_root_dir $package_key] if { [file exists $old_package_path] } { - # Backup existing (old) package in packages dir first - exec "mv" "$old_package_path" "${old_package_path}.bak" + util::backup_file -file_path $old_package_path } # Move the package into the packages dir Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.50 -r1.51 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 2 Oct 2003 12:18:51 -0000 1.50 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 2 Oct 2003 14:32:22 -0000 1.51 @@ -4404,6 +4404,47 @@ #################### # +# Procs in the util namespace +# +#################### + +ad_proc -public util::backup_file { + {-file_path:required} + {-backup_suffix ".bak"} +} { + Backs up (move) the file or directory with given path to a file/directory with a backup suffix. + Will avoid overwriting old backup files by adding a number to the filename to make it unique. + For example, suppose you are backing up /web/my-server/packages/my-package/file.txt and + the file has already been backed up to /web/my-server/packages/my-package/file.txt.bak. Invoking + this proc will then generate the backup file /web/my-server/packages/my-package/file.txt.bak.2 + + @param backup_suffix The suffix to add to the backup file. + + @author Peter Marklund +} { + # Keep generating backup paths until we find one that doesn't already exist + set backup_counter 1 + while 1 { + if { $backup_counter == "1" } { + set backup_path "${file_path}${backup_suffix}" + } else { + set backup_path "${file_path}${backup_suffix}.${backup_counter}" + } + + if { ![file exists $backup_path] } { + # We found a non-existing backup path + break + } + + incr backup_counter + } + + exec "mv" "$file_path" "$backup_path" +} + + +#################### +# # Procs in the util::whos_online namespace # ####################