MacPorts 2.11.0: oddly named workdirs

Joshua Root jmr at macports.org
Mon Jul 14 12:25:47 UTC 2025


On 14/7/2025 21:21, Chris Jones wrote:
> 
> I think this is effectively the only fix, find a way to have something 
> slightly less random than we have now. Maybe some sort of string hash of 
> meta-data related to the port that results in a 'random' string but one 
> that doesn't change if the port is rebuilt with no portfile changes, or 
> just small ones (that don't e.g. change the port version or things like 
> that).
Try this.

- Josh
-------------- next part --------------
diff --git a/src/port1.0/portutil.tcl b/src/port1.0/portutil.tcl
index 4b52d019e..4b096005d 100644
--- a/src/port1.0/portutil.tcl
+++ b/src/port1.0/portutil.tcl
@@ -1737,9 +1737,17 @@ proc portutil::create_workpath {} {
     file mkdir $portbuildpath
     # Create and link build dir if link or link target are missing or wrong type.
     if {[catch {file type $subbuildpath} ftype] || $ftype eq "directory" || ![file isdirectory $subbuildpath]} {
-        # This doesn't need to be unguessable, just unique (and short). Four
-        # random characters is enough for ~1.7M build dirs. Posix calls for 6.
-        set shortpath [mkdtemp [file dirname $portbuildpath]/[string range $subport 0 3]XXXXXX]
+        # First try a deterministic short name based on subbuildpath
+        package require sha1
+        set shortpath [file dirname $portbuildpath]/[string range $subport 0 3][string range [::sha1::sha1 -hex -- $subbuildpath] 0 5]
+        # If the name is already taken, generate a random unique one with mkdtemp.
+        if {[file exists $shortpath]} {
+            # This doesn't need to be unguessable, just unique (and short). Four
+            # random characters is enough for ~1.7M build dirs. Posix calls for 6.
+            set shortpath [mkdtemp [file dirname $portbuildpath]/[string range $subport 0 3]XXXXXX]
+        } else {
+            file mkdir $shortpath
+        }
         if {$ftype eq "directory"} {
             delete $shortpath
             file rename $subbuildpath $shortpath


More information about the macports-dev mailing list