Changeset 125007


Ignore:
Timestamp:
Sep 2, 2014, 5:47:55 PM (5 years ago)
Author:
ksammons@…
Message:

base: Refactor distfile walking code in reclaim to avoid deleting outside the root path.
https://lists.macosforge.org/pipermail/macports-dev/2014-August/027811.html

Location:
trunk/base
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/doc/port-doctor.1

    r124485 r125007  
    11'\" t
    2 .TH "PORT\-DOCTOR" "1" "08/24/2014" "MacPorts 2\&.3\&.99" "MacPorts Manual"
     2.TH "PORT\-DOCTOR" "1" "09/02/2014" "MacPorts 2\&.3\&.99" "MacPorts Manual"
    33.\" -----------------------------------------------------------------
    44.\" * Define some portability stuff
  • trunk/base/doc/port-reclaim.1

    r124485 r125007  
    11'\" t
    2 .TH "PORT\-RECLAIM" "1" "08/24/2014" "MacPorts 2\&.3\&.99" "MacPorts Manual"
     2.TH "PORT\-RECLAIM" "1" "09/02/2014" "MacPorts 2\&.3\&.99" "MacPorts Manual"
    33.\" -----------------------------------------------------------------
    44.\" * Define some portability stuff
  • trunk/base/src/macports1.0/reclaim.tcl

    r124153 r125007  
    9898        set home_dist       ${macports::user_home}/.macports/$root_dist
    9999
    100 
    101         # If the directory is empty, and this isn't the root folder, delete it and recursively go up directories until a non-empty one is found.
    102         if { $dir ne $root_dist && $dir ne $home_dist && [readdir $dir] eq ""} {
    103 
    104             set up_dir [file dirname $dir]
    105 
    106             ui_msg "Found empty directory: $dir. Attempting to delete."
    107 
    108             if {[catch {file delete -force $dir} error] } {
    109                 ui_error "something went wrong when trying to delete $dir"
    110             }
    111 
    112             walk_files $up_dir $delete $dist_paths
    113             return
    114         }
    115 
    116100        foreach item [readdir $dir] {
    117 
    118101            set currentPath [file join $dir $item]
    119102
    120103            if {[file isdirectory $currentPath]} {
    121 
    122104                walk_files $currentPath $delete $dist_paths
    123 
    124105            } else {
    125                
    126106                # If the current file isn't in the known-installed-distfiles
    127107                if {[lsearch $dist_paths $currentPath] == -1} {
    128108                    set found_distfile yes
    129109
    130                     ui_msg "Found distfile: $item"
     110                    ui_msg "Found unused distfile: $item"
    131111
    132112                    if {$delete eq "yes"} {
    133 
    134113                        ui_debug "Deleting file: $item"
    135114                        ui_msg "Removing distfile: $item"
    136115
    137116                        if {[catch {file delete $currentPath} error]} {
    138                             ui_error "something went wrong when trying to delete $currentPath"
    139                         }
    140 
    141                         # If the directory is now empty, recursively call on this directory, to delete it.
    142                         if {[is_empty_dir $dir]} {
    143 
    144                             ui_debug "Current directory is empty. Walking to $dir"
    145                             walk_files $dir $delete $dist_paths
     117                            ui_error "something went wrong when trying to delete $currentPath: $error"
    146118                        }
    147119                    }
    148120                }
     121            }
     122        }
     123
     124        if {$dir ne $root_dist && $dir ne $home_dist && [llength [readdir $dir]] == 0} {
     125            # If the directory is empty, and this isn't the root folder, delete
     126            # it.
     127            ui_msg "Found empty directory: $dir. Attempting to delete."
     128
     129            if {[catch {file delete -force $dir} error] } {
     130                ui_error "something went wrong when trying to delete $dir: $error"
    149131            }
    150132        }
Note: See TracChangeset for help on using the changeset viewer.