From 273623d0884cd799f7bd1ed7e56e22750238c056 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 24 Aug 2026 12:32:14 +0000 Subject: [PATCH] Exclude Linux core dumps from backups by default (#538) Add the core.* pattern to the default folder-exclusion list so Linux core dump files are excluded from backups out of the box, avoiding oversized archives. Users can still override or remove this default via the existing Files and Folders exclusion settings. Add PHPUnit coverage for the new default, the core.* match behavior, and user overrides. Co-authored-by: sourabh-imh --- ...boldgrid-backup-admin-folder-exclusion.php | 2 +- ...boldgrid-backup-admin-folder-exclusion.php | 136 ++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/admin/test-class-boldgrid-backup-admin-folder-exclusion.php diff --git a/admin/class-boldgrid-backup-admin-folder-exclusion.php b/admin/class-boldgrid-backup-admin-folder-exclusion.php index 6bd0a7ef..43ac544e 100644 --- a/admin/class-boldgrid-backup-admin-folder-exclusion.php +++ b/admin/class-boldgrid-backup-admin-folder-exclusion.php @@ -26,7 +26,7 @@ class Boldgrid_Backup_Admin_Folder_Exclusion { * @since 1.6.0 * @var string */ - public $default_exclude = '.git,node_modules,wp-content/cache'; + public $default_exclude = '.git,node_modules,wp-content/cache,core.*'; /** * The default include value. diff --git a/tests/admin/test-class-boldgrid-backup-admin-folder-exclusion.php b/tests/admin/test-class-boldgrid-backup-admin-folder-exclusion.php new file mode 100644 index 00000000..4716151b --- /dev/null +++ b/tests/admin/test-class-boldgrid-backup-admin-folder-exclusion.php @@ -0,0 +1,136 @@ + + */ + +/** + * Class: Test_Boldgrid_Backup_Admin_Folder_Exclusion + * + * @since SINCEVERSION + */ +class Test_Boldgrid_Backup_Admin_Folder_Exclusion extends WP_UnitTestCase { + /** + * Get a fresh folder exclusion object. + * + * @since SINCEVERSION + * + * @return Boldgrid_Backup_Admin_Folder_Exclusion + */ + private function get_folder_exclusion() { + $core = new Boldgrid_Backup_Admin_Core(); + + // Ensure we are not in a forced "full backup" state, which bypasses stored/custom values. + $core->is_backup_full = false; + $core->is_archiving_update_protection = false; + $core->pre_auto_update = false; + $core->is_backup_now = false; + + return new Boldgrid_Backup_Admin_Folder_Exclusion( $core ); + } + + /** + * Test that Linux core dumps are excluded by default. + * + * Issue #538: exclude Linux core dump files (core.*) from backups by default. + * + * @since SINCEVERSION + */ + public function test_core_dumps_in_default_exclude() { + $folder_exclusion = $this->get_folder_exclusion(); + + $this->assertStringContainsString( + 'core.*', + $folder_exclusion->default_exclude, + 'The default exclude list should contain the core.* pattern.' + ); + } + + /** + * Test the core.* pattern matches Linux core dump filenames. + * + * @since SINCEVERSION + */ + public function test_core_dump_pattern_matches() { + $folder_exclusion = $this->get_folder_exclusion(); + + // Core dumps in the root and in subdirectories should match. + $this->assertTrue( $folder_exclusion->is_match( 'core.*', 'core.12345' ) ); + $this->assertTrue( $folder_exclusion->is_match( 'core.*', 'wp-content/uploads/core.98765' ) ); + $this->assertTrue( $folder_exclusion->is_match( 'core.*', 'core.' ) ); + + // Unrelated files that merely contain "core" should not match. + $this->assertFalse( $folder_exclusion->is_match( 'core.*', 'wp-content/plugins/core-plugin/file.php' ) ); + $this->assertFalse( $folder_exclusion->is_match( 'core.*', 'wp-content/plugins/mycore.php' ) ); + $this->assertFalse( $folder_exclusion->is_match( 'core.*', 'wp-includes/index.php' ) ); + } + + /** + * Test that a core dump file is excluded when using the default settings. + * + * @since SINCEVERSION + */ + public function test_core_dump_excluded_by_default() { + $folder_exclusion = $this->get_folder_exclusion(); + + // Simulate default include/exclude settings. + $folder_exclusion->include = '*'; + $folder_exclusion->exclude = $folder_exclusion->default_exclude; + + $this->assertFalse( + $folder_exclusion->allow_file( 'wp-content/uploads/core.12345' ), + 'A Linux core dump should be excluded when using the default exclude settings.' + ); + + // A normal file should still be allowed. + $this->assertTrue( + $folder_exclusion->allow_file( 'wp-content/uploads/photo.png' ), + 'A normal file should be included when using the default settings.' + ); + } + + /** + * Test that users can override the default and keep core dumps in their backup. + * + * @since SINCEVERSION + */ + public function test_core_dump_included_when_default_overridden() { + $folder_exclusion = $this->get_folder_exclusion(); + + // User removed core.* from their exclude list. + $folder_exclusion->include = '*'; + $folder_exclusion->exclude = '.git,node_modules,wp-content/cache'; + + $this->assertTrue( + $folder_exclusion->allow_file( 'wp-content/uploads/core.12345' ), + 'A Linux core dump should be included when the user overrides the default exclude settings.' + ); + } + + /** + * Test that the default exclude value can be filtered. + * + * @since SINCEVERSION + */ + public function test_default_exclude_is_filterable() { + $callback = function () { + return '.git,node_modules'; + }; + + add_filter( 'boldgrid_backup_default_folder_exclude', $callback ); + + $folder_exclusion = $this->get_folder_exclusion(); + + $this->assertEquals( '.git,node_modules', $folder_exclusion->default_exclude ); + + remove_filter( 'boldgrid_backup_default_folder_exclude', $callback ); + } +}