You've already forked macports-base
mirror of
https://github.com/macports/macports-base.git
synced 2026-07-12 18:18:43 -07:00
Avoid deleting files on worker threads
Instead, clean up the temp files on the main thread after getting the fetch results. Still deleting on workers in the case of cancellation, since the whole program may be about to exit when that happens.
This commit is contained in:
@@ -177,12 +177,10 @@ namespace eval mport_fetch_thread {
|
||||
break
|
||||
}
|
||||
}
|
||||
foreach sigtype $sigtypes {
|
||||
if {!$sig_fetched || $sigtype ne $fetched_sigtype} {
|
||||
if {$cancelled} {
|
||||
foreach sigtype $sigtypes {
|
||||
catch {file delete ${outpath}.${sigtype}}
|
||||
}
|
||||
}
|
||||
if {!$archive_fetched} {
|
||||
catch {file delete ${outpath}.TMP}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +216,7 @@ namespace eval mport_fetch_thread {
|
||||
}
|
||||
}
|
||||
}
|
||||
if {!$fetched} {
|
||||
if {$cancelled} {
|
||||
catch {file delete ${outpath}.TMP}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,22 +245,26 @@ proc portarchivefetch::fetchfiles {{async no} args} {
|
||||
variable async_job
|
||||
variable async_logid
|
||||
|
||||
set incoming_path [file join ${portdbpath} incoming]
|
||||
|
||||
if {[info exists async_job]} {
|
||||
if {$async} {
|
||||
# Async fetch already started
|
||||
return 0
|
||||
}
|
||||
lassign $async_job jobid tmpfiles
|
||||
unset async_job
|
||||
# Fetch was started asynchronously, wait for job to finish
|
||||
if {![curlwrap_async_is_complete $async_job]} {
|
||||
if {![curlwrap_async_is_complete $jobid]} {
|
||||
# Display progress for this fetch while waiting for it to finish
|
||||
curlwrap_async_show_progress $async_job
|
||||
curlwrap_async_show_progress $jobid
|
||||
# Loop with a reasonable timeout so we don't wait too long
|
||||
# to handle events like signals.
|
||||
while {![curlwrap_async_is_complete $async_job 500]} {}
|
||||
while {![curlwrap_async_is_complete $jobid 500]} {}
|
||||
}
|
||||
lassign [curlwrap_async_result $async_job] status result
|
||||
unset async_job
|
||||
lassign [curlwrap_async_result $jobid] status result
|
||||
if {$status != 0} {
|
||||
file delete {*}$tmpfiles
|
||||
if {[tbool ports_binary_only] || [_archive_available]} {
|
||||
error "Failed to fetch archive for [option subport]: $result"
|
||||
} else {
|
||||
@@ -282,7 +286,6 @@ proc portarchivefetch::fetchfiles {{async no} args} {
|
||||
}
|
||||
}
|
||||
}
|
||||
set incoming_path [file join ${portdbpath} incoming]
|
||||
chownAsRoot $incoming_path
|
||||
if {[info exists elevated] && $elevated eq "yes"} {
|
||||
dropPrivileges
|
||||
@@ -361,10 +364,13 @@ proc portarchivefetch::fetchfiles {{async no} args} {
|
||||
file delete -force $archive_tmp_path
|
||||
touch $archive_tmp_path
|
||||
chownAsRoot $archive_tmp_path
|
||||
set tmpfiles [list $archive_tmp_path]
|
||||
foreach sigtype $sigtypes {
|
||||
file delete -force ${incoming_path}/${archive}.${sigtype}
|
||||
touch ${incoming_path}/${archive}.${sigtype}
|
||||
chownAsRoot ${incoming_path}/${archive}.${sigtype}
|
||||
set sigpath ${incoming_path}/${archive}.${sigtype}
|
||||
lappend tmpfiles $sigpath
|
||||
file delete -force $sigpath
|
||||
touch $sigpath
|
||||
chownAsRoot $sigpath
|
||||
}
|
||||
if {[tbool ports_binary_only] || [_archive_available]} {
|
||||
set this_urlmap $urlmap($url_var)
|
||||
@@ -373,10 +379,11 @@ proc portarchivefetch::fetchfiles {{async no} args} {
|
||||
set this_urlmap [lrange $urlmap($url_var) 0 2]
|
||||
set maxfails 3
|
||||
}
|
||||
set async_job [curlwrap_async fetch_archive $credentials $fetch_options $this_urlmap \
|
||||
set jobid [curlwrap_async fetch_archive $credentials $fetch_options $this_urlmap \
|
||||
[lmap site $this_urlmap {portfetch::assemble_url \
|
||||
[expr {[string index $site end] eq "/" ? $site : "${site}/"}]${archive.subdir} $archive}] \
|
||||
${incoming_path}/${archive} $sigtypes $maxfails $async_logid]
|
||||
set async_job [list $jobid $tmpfiles]
|
||||
return 0
|
||||
} else {
|
||||
foreach site $urlmap($url_var) {
|
||||
@@ -519,7 +526,7 @@ proc portarchivefetch::archivefetch_async_start {logid} {
|
||||
proc portarchivefetch::_async_cleanup {} {
|
||||
variable async_job
|
||||
if {[info exists async_job]} {
|
||||
curlwrap_async_cancel $async_job
|
||||
curlwrap_async_cancel [lindex $async_job 0]
|
||||
unset async_job
|
||||
}
|
||||
}
|
||||
|
||||
+33
-11
@@ -468,22 +468,44 @@ proc portfetch::fetchfiles {{async no} args} {
|
||||
set async_jobs_copy $async_jobs
|
||||
# Ensure we don't try to get results for jobs twice
|
||||
unset async_jobs
|
||||
set any_failed 0
|
||||
foreach {distfile jobid} $async_jobs_copy {
|
||||
set cancelled 0
|
||||
if {![curlwrap_async_is_complete $jobid]} {
|
||||
# Display progress for this fetch while waiting for it to finish
|
||||
curlwrap_async_show_progress $jobid
|
||||
# Loop with a reasonable timeout so we don't wait too long
|
||||
# to handle events like signals.
|
||||
while {![curlwrap_async_is_complete $jobid 500]} {}
|
||||
if {!$any_failed} {
|
||||
# Display progress for this fetch while waiting for it to finish
|
||||
curlwrap_async_show_progress $jobid
|
||||
# Loop with a reasonable timeout so we don't wait too long
|
||||
# to handle events like signals.
|
||||
while {![curlwrap_async_is_complete $jobid 500]} {}
|
||||
} else {
|
||||
# If something failed, stop other incomplete jobs so we fail fast
|
||||
curlwrap_async_cancel $jobid
|
||||
set cancelled 1
|
||||
}
|
||||
}
|
||||
lassign [curlwrap_async_result $jobid] status result
|
||||
if {$status != 0} {
|
||||
error "Failed to fetch ${distfile}: $result"
|
||||
}
|
||||
if {![file exists ${distpath}/${distfile}]} {
|
||||
file rename -force ${distpath}/${distfile}.TMP ${distpath}/${distfile}
|
||||
if {!$cancelled} {
|
||||
lassign [curlwrap_async_result $jobid] status result
|
||||
if {$status != 0} {
|
||||
# Some ports have a lot of distfiles, so don't print an
|
||||
# error for all of them outside of debug mode.
|
||||
if {!$any_failed} {
|
||||
ui_error "Failed to fetch ${distfile}: $result"
|
||||
} else {
|
||||
ui_debug "Failed to fetch ${distfile}: $result"
|
||||
}
|
||||
set any_failed 1
|
||||
file delete -force ${distpath}/${distfile}.TMP
|
||||
} elseif {![file exists ${distpath}/${distfile}]} {
|
||||
file rename -force ${distpath}/${distfile}.TMP ${distpath}/${distfile}
|
||||
}
|
||||
} else {
|
||||
file delete -force ${distpath}/${distfile}.TMP
|
||||
}
|
||||
}
|
||||
if {$any_failed} {
|
||||
error "Failed to fetch distfiles"
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user