Skip to content

Commit 42cc62d

Browse files
committed
fix(backup): detect S3 rclone backend by exact type, not substring
Addresses review feedback: S3 detection ran 'rclone config show easyengine | grep type' and substring-matched 's3', which (a) hardcoded the easyengine remote name and so missed any backend configured via a different rclone-path, and (b) could false-positive on any config line whose value merely contained 's3' (e.g. an endpoint host or a content type), wrongly enabling S3 multipart tuning on a non-S3 remote. Extract detection into is_s3_remote(), which resolves the remote name from rclone-path and compares the backend's exact type value to s3. All S3-compatible providers (AWS, Spaces, Wasabi, MinIO, ...) use type = s3, so the exact match still covers them.
1 parent 10876d9 commit 42cc62d

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/helper/Site_Backup_Restore.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,13 +1356,35 @@ private function rclone_download( $path ) {
13561356
}
13571357

13581358

1359+
/**
1360+
* Whether the configured rclone remote is an S3 backend.
1361+
*
1362+
* Resolves the remote name from `rclone-path` (instead of assuming
1363+
* `easyengine`) and compares the backend's exact `type` value to `s3`,
1364+
* rather than substring-matching the raw `rclone config show` output -- which
1365+
* could both miss a non-`easyengine` remote and false-positive on any line
1366+
* whose value merely contains the substring `s3`. All S3-compatible providers
1367+
* (AWS, Spaces, Wasabi, MinIO, ...) share `type = s3`, so an exact match on
1368+
* the type value covers them.
1369+
*
1370+
* @return bool
1371+
*/
1372+
private function is_s3_remote() {
1373+
$rclone_path = get_config_value( 'rclone-path', 'easyengine:easyengine' );
1374+
$remote = explode( ':', $rclone_path )[0];
1375+
1376+
$command = sprintf( "rclone config show %s | awk -F '=' '/^[[:space:]]*type[[:space:]]*=/ {gsub(/[[:space:]]/, \"\", \$2); print \$2; exit}'", escapeshellarg( $remote ) );
1377+
$type = trim( EE::launch( $command )->stdout );
1378+
1379+
return ( 's3' === $type );
1380+
}
1381+
13591382
private function rclone_upload( $path ) {
13601383
$cpu_cores = intval( EE::launch( 'nproc' )->stdout );
13611384
$available_ram = $this->get_available_ram_mb();
13621385

13631386
// Detect S3 backends, which require additional multipart-upload tuning.
1364-
$rclone_type = EE::launch( 'rclone config show easyengine | grep type' )->stdout;
1365-
$is_s3 = ( strpos( $rclone_type, 's3' ) !== false );
1387+
$is_s3 = $this->is_s3_remote();
13661388

13671389
$res = $this->compute_rclone_resources( $cpu_cores, $available_ram, $is_s3 );
13681390
$transfers = $res['transfers'];

0 commit comments

Comments
 (0)