Skip to content

Commit 33111db

Browse files
authored
Merge branch 'master' into local_mode
2 parents b4ebc8c + 17defca commit 33111db

6 files changed

Lines changed: 159 additions & 53 deletions

File tree

ChangeLog

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ Release 2.13.0 (unreleased)
77
phases as a regular user using work, distfiles, and logs under the
88
Portfile directory without modifying the MacPorts installation.
99
(perry)
10+
11+
- Added a --purge option for 'port clean' that quickly and
12+
unconditionally deletes all files of the chosen type(s).
13+
(jmr in 22e1abd)
1014

1115
- Added a -T flag to prepend ISO 8601 timestamps to each line of
1216
output, and elapsed time logging for each phase.
1317
(#2020, herbygillot in 037d168)
1418

15-
- Update the bundled copy of Tcl to version 9.0.3. (jmr in d875700)
16-
1719
- Add blake3 as new supported checksum type.
1820
(#63885, herbygillot in 1dadbbf8b)
1921

2022
- Add livecheck.user_agent option.
2123
(#64369, herbygillot in 0d4b57b05)
2224

25+
- Update the bundled copy of Tcl to version 9.0.3. (jmr in d875700)
26+
2327
- Fix trace mode on arm64 for macOS > 14.
2428
(#66358, cal in aacd364)
2529

doc/port-clean.1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ port-clean \- Remove temporary files used to build a port\&.
2525
.sp
2626
.nf
2727
\fBport\fR [\fB\-vdqypotf\fR] [\fB\-D\fR \fIportdir\fR] \fBclean\fR
28-
[\-\-archive] [\-\-dist] [\-\-logs] [\-\-work] [\-\-all]
28+
[\-\-archive] [\-\-dist] [\-\-logs] [\-\-work] [\-\-all] [\-\-purge]
2929
[[\fIportname\fR | \fIpseudo\-portname\fR | \fIport\-expressions\fR | \fIport\-url\fR]]
3030
.fi
3131
.SH "DESCRIPTION"
@@ -123,6 +123,13 @@ Remove all temporary files\&. The same as specifying
123123
\fB\-\-logs\fR, and
124124
\fB\-\-work\fR\&.
125125
.RE
126+
.PP
127+
\fB\-\-purge\fR
128+
.RS 4
129+
Remove all temporary files of the chosen types, regardless of which port(s) they are associated with\&. This is much faster than e\&.g\&. "port clean \-\-all all" and will also delete files created by ports that do not exist in the current ports tree\&.
130+
131+
No ports need to be specified when using this option, and specifying ports has no effect, since all ports\*(Aq files are deleted regardless\&. This option combines with other options as you would expect, so the default is to delete all work directories, "port clean \-\-logs \-\-purge" will delete all logs, and so on\&.
132+
.RE
126133
.SH "GLOBAL OPTIONS"
127134
.sp
128135
Please see the section \fBGLOBAL OPTIONS\fR in the \fBport\fR(1) man page for a description of global port options\&.

doc/port-clean.1.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[cmdsynopsis]
1212
*port* [*-vdqypotf*] [*-D* 'portdir'] *clean*
13-
[--archive] [--dist] [--logs] [--work] [--all]
13+
[--archive] [--dist] [--logs] [--work] [--all] [--purge]
1414
[['portname' | 'pseudo-portname' | 'port-expressions' | 'port-url']]
1515

1616
DESCRIPTION
@@ -59,6 +59,17 @@ OPTIONS
5959
Remove all temporary files. The same as specifying *--archive*, *--dist*,
6060
*--logs*, and *--work*.
6161
62+
*--purge*::
63+
Remove all temporary files of the chosen types, regardless of which port(s)
64+
they are associated with. This is much faster than e.g. "port clean --all
65+
all" and will also delete files created by ports that do not exist in the
66+
current ports tree.
67+
+
68+
No ports need to be specified when using this option, and specifying ports
69+
has no effect, since all ports' files are deleted regardless. This option
70+
combines with other options as you would expect, so the default is to
71+
delete all work directories, "port clean --logs --purge" will delete all
72+
logs, and so on.
6273
6374
include::global-flags.txt[]
6475

src/macports1.0/macports.tcl

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ namespace eval macports {
9292
# Options set in the portfile interpreter but only in system_options
9393
variable portinterp_private_options [list clonebin_path macosx_sdk_path]
9494

95+
# Directories in portdbpath that are publicly known
96+
variable wellknown_dirs [dict create build 1 distfiles 1 incoming 1 logs 1 registry 1 software 1 sources 1]
97+
9598
# Only used via override_vars
9699
variable macosx_sdk_path
97100

@@ -3522,6 +3525,16 @@ proc _source_is_obsolete_svn_repo {source_dir} {
35223525
return 0
35233526
}
35243527

3528+
# Get path to a well-known directory used by MacPorts
3529+
proc macports::get_dir_path {dir} {
3530+
variable wellknown_dirs
3531+
if {![dict exists $wellknown_dirs $dir]} {
3532+
error "Unknown directory: $dir"
3533+
}
3534+
variable portdbpath
3535+
return [file join $portdbpath $dir]
3536+
}
3537+
35253538
proc macports::getportbuildpath {id {portname {}}} {
35263539
package require sha1
35273540
variable portdbpath
@@ -3802,6 +3815,49 @@ proc macports::verify_ports_signature {path} {
38023815
error "No known key verified signature for $path"
38033816
}
38043817

3818+
# Helper to delete files in the given ports tree dir that are not in
3819+
# the given tarball or are updated in the tarball.
3820+
proc macports::delete_ports_not_in_tarball {extractdir tarball} {
3821+
# First move the PortIndex to avoid deleting it.
3822+
set indexfile ${extractdir}/ports/PortIndex
3823+
if {[file isfile $indexfile]} {
3824+
file mkdir ${extractdir}/tmp
3825+
file rename -force $indexfile ${extractdir}/tmp/
3826+
if {[file isfile ${indexfile}.quick]} {
3827+
file rename -force ${indexfile}.quick ${extractdir}/tmp/
3828+
}
3829+
}
3830+
package require tar
3831+
set tarfiles [::tar::stat $tarball]
3832+
set subpath_start [expr {[string length $extractdir] + 1}]
3833+
fs-traverse -depth f [list ${extractdir}/ports] {
3834+
set subpath [string range $f $subpath_start end]
3835+
file lstat $f statinfo
3836+
if {$statinfo(type) eq "directory"} {
3837+
append subpath /
3838+
}
3839+
if {![dict exists $tarfiles $subpath]
3840+
|| [dict get $tarfiles $subpath type] ne $statinfo(type)
3841+
|| ($statinfo(type) ne "directory" && [dict get $tarfiles $subpath mtime] != $statinfo(mtime))
3842+
|| ($statinfo(type) eq "file" && [dict get $tarfiles $subpath size] != $statinfo(size))
3843+
|| ($statinfo(type) eq "link" && [dict get $tarfiles $subpath linkname] ne [file readlink $f])
3844+
} then {
3845+
file delete -force $f
3846+
}
3847+
}
3848+
# Put PortIndex back
3849+
if {[file isfile ${extractdir}/tmp/PortIndex]} {
3850+
set cur_uid [getuid]
3851+
file rename -force ${extractdir}/tmp/PortIndex $indexfile
3852+
chown $indexfile $cur_uid
3853+
if {[file isfile ${extractdir}/tmp/PortIndex.quick]} {
3854+
file rename -force ${extractdir}/tmp/PortIndex.quick ${indexfile}.quick
3855+
chown ${indexfile}.quick $cur_uid
3856+
}
3857+
}
3858+
file delete -force ${extractdir}/tmp
3859+
}
3860+
38053861
proc mportsync {{options {}}} {
38063862
global macports::sources macports::ui_prefix \
38073863
macports::os_platform macports::os_major \
@@ -3969,43 +4025,7 @@ proc mportsync {{options {}}} {
39694025
set kflag {}
39704026
} else {
39714027
# Extract only updated files, and delete ones not in the tarball.
3972-
# First move the PortIndex to avoid deleting it.
3973-
if {[file isfile $indexfile]} {
3974-
file mkdir ${extractdir}/tmp
3975-
file rename -force $indexfile ${extractdir}/tmp/
3976-
if {[file isfile ${indexfile}.quick]} {
3977-
file rename -force ${indexfile}.quick ${extractdir}/tmp/
3978-
}
3979-
}
3980-
package require tar
3981-
set tarfiles [::tar::stat $tarball]
3982-
set subpath_start [expr {[string length $extractdir] + 1}]
3983-
fs-traverse -depth f [list ${extractdir}/ports] {
3984-
set subpath [string range $f $subpath_start end]
3985-
file lstat $f statinfo
3986-
if {$statinfo(type) eq "directory"} {
3987-
append subpath /
3988-
}
3989-
if {![dict exists $tarfiles $subpath]
3990-
|| [dict get $tarfiles $subpath type] ne $statinfo(type)
3991-
|| ($statinfo(type) ne "directory" && [dict get $tarfiles $subpath mtime] != $statinfo(mtime))
3992-
|| ($statinfo(type) eq "file" && [dict get $tarfiles $subpath size] != $statinfo(size))
3993-
|| ($statinfo(type) eq "link" && [dict get $tarfiles $subpath linkname] ne [file readlink $f])
3994-
} then {
3995-
file delete -force $f
3996-
}
3997-
}
3998-
unset tarfiles
3999-
# Put PortIndex back
4000-
if {[file isfile ${extractdir}/tmp/PortIndex]} {
4001-
file rename -force ${extractdir}/tmp/PortIndex $indexfile
4002-
macports::chown $indexfile $cur_uid
4003-
if {[file isfile ${extractdir}/tmp/PortIndex.quick]} {
4004-
file rename -force ${extractdir}/tmp/PortIndex.quick ${indexfile}.quick
4005-
macports::chown ${indexfile}.quick $cur_uid
4006-
}
4007-
}
4008-
file delete -force ${extractdir}/tmp
4028+
macports::delete_ports_not_in_tarball $extractdir $tarball
40094029
# use -k if supported to skip extracting files that exist
40104030
global macports::prefix_frozen
40114031
if {[string match ${prefix_frozen}/bin/* $tar]} {
@@ -4092,7 +4112,8 @@ proc mportsync {{options {}}} {
40924112
# sync a port snapshot tarball
40934113
set indexfile [macports::getindex $source]
40944114
set destdir [file dirname $indexfile]
4095-
set tarpath [file join [file normalize [file join $destdir ..]] $filename]
4115+
set tardir [file dirname $destdir]
4116+
set tarpath [file join $tardir $filename]
40964117

40974118
set updated 1
40984119
if {[file isdirectory $destdir]} {
@@ -4116,7 +4137,7 @@ proc mportsync {{options {}}} {
41164137
set progressflag {}
41174138
if {$portverbose} {
41184139
set progressflag [list --progress builtin]
4119-
set verboseflag "-v"
4140+
set verboseflag v
41204141
} elseif {[info exists ui_options(progress_download)]} {
41214142
set progressflag [list --progress $ui_options(progress_download)]
41224143
set verboseflag ""
@@ -4142,13 +4163,39 @@ proc mportsync {{options {}}} {
41424163
continue
41434164
}
41444165

4166+
set tar {}
4167+
global macports::hfscompression
4168+
if {${hfscompression} && [getuid] == 0} {
4169+
ui_debug "Using bsdtar with HFS+ compression (if valid)"
4170+
set tar [macports::find_tar_with_hfscompression]
4171+
}
4172+
if {$tar ne {}} {
4173+
set tar "$tar --hfsCompression"
4174+
} else {
4175+
set tar [macports::findBinary tar $tar_path]
4176+
}
4177+
# Simply extract if there is no existing ports tree
4178+
if {[llength [glob -nocomplain -directory $destdir *]] == 0} {
4179+
set kflag {}
4180+
} else {
4181+
# Extract only updated files, and delete ones not in the tarball.
4182+
macports::delete_ports_not_in_tarball $tardir $tarpath
4183+
# use -k if supported to skip extracting files that exist
4184+
global macports::prefix_frozen
4185+
if {[string match ${prefix_frozen}/bin/* $tar]} {
4186+
set kflag k
4187+
} else {
4188+
set kflag $::macports::autoconf::tar_k
4189+
}
4190+
}
4191+
41454192
set extflag {}
41464193
switch -- $extension {
41474194
{tar.gz} {
4148-
set extflag -z
4195+
set extflag z
41494196
}
41504197
{tar.bz2} {
4151-
set extflag -j
4198+
set extflag j
41524199
}
41534200
}
41544201

@@ -4157,9 +4204,8 @@ proc mportsync {{options {}}} {
41574204
# as top-level directory name.
41584205
set striparg "--strip-components=1"
41594206

4160-
set tar [macports::findBinary tar $tar_path]
41614207
if {[catch {
4162-
system -W ${destdir} "$tar $verboseflag $striparg $extflag -xf [macports::shellescape $tarpath]"
4208+
system -W $destdir "$tar $striparg -x${extflag}${kflag}${verboseflag}f [macports::shellescape $tarpath]"
41634209
} error]} {
41644210
ui_error "Extracting $source failed ($error)"
41654211
incr numfailed
@@ -4177,7 +4223,7 @@ proc mportsync {{options {}}} {
41774223
set needs_portindex true
41784224
}
41794225

4180-
file delete $tarpath
4226+
file delete $tarpath ${tarpath}.sig
41814227
}
41824228
{^mports$} {
41834229
ui_error "Synchronization using the mports protocol no longer supported."

src/port/port.tcl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,6 +3941,44 @@ proc action_sync { action portlist opts } {
39413941
}
39423942

39433943

3944+
proc action_clean {action portlist opts} {
3945+
if {![dict exists $opts ports_clean_purge]} {
3946+
return [action_target $action $portlist $opts]
3947+
}
3948+
# handle --purge (delete all files in the relevant dirs)
3949+
if {[dict exists $opts ports_clean_archive] || [dict exists $opts ports_clean_all]} {
3950+
set archives_dir [macports::get_dir_path incoming]
3951+
set to_delete [glob -directory $archives_dir -types f *]
3952+
set verified_dir [file join $archives_dir verified]
3953+
lappend to_delete {*}[glob -directory $verified_dir -types f *]
3954+
foreach f $to_delete {
3955+
ui_info "Deleting $f"
3956+
file delete $f
3957+
}
3958+
}
3959+
set delete_dirs [list]
3960+
if {[dict exists $opts ports_clean_dist] || [dict exists $opts ports_clean_all]} {
3961+
lappend delete_dirs [macports::get_dir_path distfiles]
3962+
}
3963+
if {[dict exists $opts ports_clean_logs] || [dict exists $opts ports_clean_all]} {
3964+
lappend delete_dirs [macports::get_dir_path logs]
3965+
}
3966+
# Match logic in portclean: work dir is cleaned unless only --logs was requested
3967+
if {[dict exists $opts ports_clean_work] || [dict exists $opts ports_clean_all]
3968+
|| [dict exists $opts ports_clean_archive] || [dict exists $opts ports_clean_dist]
3969+
|| ![dict exists $opts ports_clean_logs]} {
3970+
lappend delete_dirs [macports::get_dir_path build]
3971+
}
3972+
foreach dir $delete_dirs {
3973+
foreach direntry [glob -directory $dir *] {
3974+
ui_info "Deleting $direntry"
3975+
file delete -force $direntry
3976+
}
3977+
}
3978+
return 0
3979+
}
3980+
3981+
39443982
proc action_target { action portlist opts } {
39453983
if {[require_portlist portlist]} {
39463984
return 1
@@ -4181,6 +4219,7 @@ set action_array [dict create \
41814219
unsetrequested [list action_setrequested $action_args::PORTS] \
41824220
setunrequested [list action_setrequested $action_args::PORTS] \
41834221
\
4222+
clean [list action_clean $action_args::PORTS] \
41844223
upgrade [list action_upgrade $action_args::PORTS] \
41854224
rev-upgrade [list action_revupgrade $action_args::NONE] \
41864225
reclaim [list action_reclaim $action_args::NONE] \
@@ -4225,7 +4264,6 @@ set action_array [dict create \
42254264
build [list action_target $action_args::PORTS] \
42264265
destroot [list action_target $action_args::PORTS] \
42274266
install [list action_target $action_args::PORTS] \
4228-
clean [list action_target $action_args::PORTS] \
42294267
test [list action_target $action_args::PORTS] \
42304268
lint [list action_target $action_args::PORTS] \
42314269
livecheck [list action_target $action_args::PORTS] \
@@ -4331,7 +4369,7 @@ set cmd_opts_array [dict create {*}{
43314369
install {allow-failing no-activate no-replace no-rev-upgrade unrequested}
43324370
uninstall {follow-dependents follow-dependencies no-exec}
43334371
variants {index}
4334-
clean {all archive dist work logs}
4372+
clean {all archive dist work logs purge}
43354373
mirror {new}
43364374
lint {nitpick}
43374375
select {list set show summary}

vendor/tcllib-2.0/modules/tar/tar.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ proc ::tar::readHeader {data} {
138138
set $x [string trim [set $x] "\x00"]
139139
}
140140
foreach x {uid gid size mtime cksum} {
141-
set $x [format %d 0[string trim [set $x] " \x00"]]
141+
set $x [format %d 0o0[string trim [set $x] " \x00"]]
142142
}
143143
set mode [string trim $mode " \x00"]
144144

@@ -149,15 +149,15 @@ proc ::tar::readHeader {data} {
149149
set $x [string trim [set $x] "\x00"]
150150
}
151151
foreach x {devmajor devminor} {
152-
set $x [format %d 0[string trim [set $x] " \x00"]]
152+
set $x [format %d 0o0[string trim [set $x] " \x00"]]
153153
}
154154
} elseif {$magic eq "ustar\x00"} {
155155
# posix tar
156156
foreach x {uname gname prefix} {
157157
set $x [string trim [set $x] "\x00"]
158158
}
159159
foreach x {devmajor devminor} {
160-
set $x [format %d 0[string trim [set $x] " \x00"]]
160+
set $x [format %d 0o0[string trim [set $x] " \x00"]]
161161
}
162162
} else {
163163
# old style tar

0 commit comments

Comments
 (0)