@@ -65,7 +65,8 @@ import {
65
65
handleArchAndPlatform ,
66
66
handlePlatformReversed ,
67
67
runModPatcher ,
68
- sanitizeVersion
68
+ sanitizeVersion ,
69
+ safeRemoveDirectory
69
70
} from './utils'
70
71
import { getSettings as getSettingsSideload } from 'backend/storeManagers/sideload/games'
71
72
import {
@@ -423,11 +424,11 @@ const findExecutables = async (folderPath: string): Promise<string[]> => {
423
424
return executables
424
425
}
425
426
426
- export function cleanUpDownload ( appName : string , directory : string ) {
427
+ export async function cleanUpDownload ( appName : string , directory : string ) {
427
428
inProgressDownloadsMap . delete ( appName )
428
429
inProgressExtractionsMap . delete ( appName )
429
430
deleteAbortController ( appName )
430
- rmSync ( directory , { recursive : true , force : true } )
431
+ await safeRemoveDirectory ( directory )
431
432
}
432
433
433
434
function getDownloadUrl ( platformInfo : PlatformConfig , appName : string ) {
@@ -523,9 +524,9 @@ async function downloadGame(
523
524
res ( )
524
525
}
525
526
526
- function onCancel ( ) {
527
+ async function onCancel ( ) {
527
528
try {
528
- cleanUpDownload ( appName , directory )
529
+ await cleanUpDownload ( appName , directory )
529
530
} catch ( err ) {
530
531
rej ( err )
531
532
}
@@ -1181,7 +1182,7 @@ export async function extract(
1181
1182
body : `Installed`
1182
1183
} )
1183
1184
1184
- cleanUpDownload ( appName , directory )
1185
+ await cleanUpDownload ( appName , directory )
1185
1186
1186
1187
sendFrontendMessage ( 'refreshLibrary' , 'hyperplay' )
1187
1188
@@ -1190,21 +1191,21 @@ export async function extract(
1190
1191
} )
1191
1192
}
1192
1193
)
1193
- extractService . once ( 'error' , ( error : Error ) => {
1194
+ extractService . once ( 'error' , async ( error : Error ) => {
1194
1195
logError ( `Extracting Error ${ error . message } ` , LogPrefix . HyperPlay )
1195
1196
1196
1197
cancelQueueExtraction ( )
1197
1198
callAbortController ( appName )
1198
1199
1199
- cleanUpDownload ( appName , directory )
1200
+ await cleanUpDownload ( appName , directory )
1200
1201
1201
1202
sendFrontendMessage ( 'refreshLibrary' , 'hyperplay' )
1202
1203
1203
1204
resolve ( {
1204
1205
status : 'error'
1205
1206
} )
1206
1207
} )
1207
- extractService . once ( 'canceled' , ( ) => {
1208
+ extractService . once ( 'canceled' , async ( ) => {
1208
1209
logInfo (
1209
1210
`Canceled Extracting: Cancellation completed on ${ appName } - Destination ${ destinationPath } ` ,
1210
1211
LogPrefix . HyperPlay
@@ -1242,7 +1243,7 @@ export async function extract(
1242
1243
body : 'Installation Stopped'
1243
1244
} )
1244
1245
1245
- cleanUpDownload ( appName , directory )
1246
+ await cleanUpDownload ( appName , directory )
1246
1247
1247
1248
sendFrontendMessage ( 'refreshLibrary' , 'hyperplay' )
1248
1249
@@ -1914,13 +1915,18 @@ async function applyPatching(
1914
1915
1915
1916
if ( signal . aborted ) {
1916
1917
logInfo ( `Patching ${ appName } aborted` , LogPrefix . HyperPlay )
1917
- rmSync ( datastoreDir , { recursive : true } )
1918
+ await safeRemoveDirectory ( datastoreDir , {
1919
+ sizeThresholdMB : blockSize * totalBlocks
1920
+ } )
1921
+ aborted = true
1918
1922
return { status : 'abort' }
1919
1923
}
1920
1924
1921
- signal . onabort = ( ) => {
1925
+ signal . onabort = async ( ) => {
1922
1926
aborted = true
1923
- rmSync ( datastoreDir , { recursive : true } )
1927
+ await safeRemoveDirectory ( datastoreDir , {
1928
+ sizeThresholdMB : blockSize * totalBlocks
1929
+ } )
1924
1930
return { status : 'abort' }
1925
1931
}
1926
1932
@@ -2005,7 +2011,36 @@ async function applyPatching(
2005
2011
}
2006
2012
// need this to cover 100% of abort cases
2007
2013
if ( aborted ) {
2008
- rmSync ( datastoreDir , { recursive : true } )
2014
+ try {
2015
+ await safeRemoveDirectory ( datastoreDir , {
2016
+ sizeThresholdMB : blockSize * totalBlocks
2017
+ } )
2018
+ } catch ( cleanupError ) {
2019
+ trackEvent ( {
2020
+ event : 'Patching Cleanup Failed' ,
2021
+ properties : {
2022
+ error : `${ cleanupError } ` ,
2023
+ game_name : gameInfo . app_name ,
2024
+ game_title : gameInfo . title ,
2025
+ platform : getPlatformName ( platform ) ,
2026
+ platform_arch : platform
2027
+ }
2028
+ } )
2029
+
2030
+ logWarning (
2031
+ `Patching aborted and cleanup failed: ${ cleanupError } ` ,
2032
+ LogPrefix . HyperPlay
2033
+ )
2034
+ }
2035
+ trackEvent ( {
2036
+ event : 'Patching Aborted' ,
2037
+ properties : {
2038
+ game_name : gameInfo . app_name ,
2039
+ game_title : gameInfo . title ,
2040
+ platform : getPlatformName ( platform ) ,
2041
+ platform_arch : platform
2042
+ }
2043
+ } )
2009
2044
return { status : 'abort' }
2010
2045
}
2011
2046
@@ -2020,8 +2055,27 @@ async function applyPatching(
2020
2055
} )
2021
2056
2022
2057
logInfo ( `Patching ${ appName } completed` , LogPrefix . HyperPlay )
2023
- rmSync ( datastoreDir , { recursive : true } )
2058
+ try {
2059
+ await safeRemoveDirectory ( datastoreDir , {
2060
+ sizeThresholdMB : blockSize * totalBlocks
2061
+ } )
2062
+ } catch ( cleanupError ) {
2063
+ trackEvent ( {
2064
+ event : 'Patching Cleanup Failed' ,
2065
+ properties : {
2066
+ error : `${ cleanupError } ` ,
2067
+ game_name : gameInfo . app_name ,
2068
+ game_title : gameInfo . title ,
2069
+ platform : getPlatformName ( platform ) ,
2070
+ platform_arch : platform
2071
+ }
2072
+ } )
2024
2073
2074
+ logWarning (
2075
+ `Patching succeeded but cleanup failed: ${ cleanupError } ` ,
2076
+ LogPrefix . HyperPlay
2077
+ )
2078
+ }
2025
2079
return { status : 'done' }
2026
2080
} catch ( error ) {
2027
2081
if ( error instanceof PatchingError ) {
@@ -2061,7 +2115,23 @@ async function applyPatching(
2061
2115
2062
2116
// errors can be thrown before datastore dir created. rmSync on nonexistent dir blocks indefinitely
2063
2117
if ( existsSync ( datastoreDir ) ) {
2064
- rmSync ( datastoreDir , { recursive : true } )
2118
+ try {
2119
+ await safeRemoveDirectory ( datastoreDir )
2120
+ } catch ( cleanupError ) {
2121
+ trackEvent ( {
2122
+ event : 'Patching Cleanup Failed' ,
2123
+ properties : {
2124
+ error : `${ cleanupError } ` ,
2125
+ game_name : gameInfo . app_name ,
2126
+ game_title : gameInfo . title
2127
+ }
2128
+ } )
2129
+
2130
+ logWarning (
2131
+ `Patching failed and cleanup failed: ${ cleanupError } ` ,
2132
+ LogPrefix . HyperPlay
2133
+ )
2134
+ }
2065
2135
}
2066
2136
2067
2137
return { status : 'error' , error : `Error while patching ${ error } ` }
0 commit comments