diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2024-02-13 13:47:12 +0100 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2024-02-13 13:47:12 +0100 |
commit | 103235888d9e74755ec4c7a72d640d4c7fabc596 (patch) | |
tree | 6ece3b4988e3254aa07996f2821dbd2c1cb11128 /src | |
parent | 0460e4ecc0fa532468331a4b71ad0fbe8ff1a416 (diff) | |
download | postgresql-103235888d9e74755ec4c7a72d640d4c7fabc596.tar.gz postgresql-103235888d9e74755ec4c7a72d640d4c7fabc596.zip |
Skip .DS_Store files in server side utils
The macOS Finder application creates .DS_Store files in directories
when opened, which creates problems for serverside utilities which
expect all files to be PostgreSQL specific files. Skip these files
when encountered in pg_checksums, pg_rewind and pg_basebackup.
This was extracted from a larger patchset for skipping hidden files
and system files, where the concencus was to just skip these. Since
this is equally likely to happen in every version, backpatch to all
supported versions.
Reported-by: Mark Guertin <markguertin@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Tobias Bussmann <t.bussmann@gmx.net>
Discussion: https://postgr.es/m/E258CE50-AB0E-455D-8AAD-BB4FE8F882FB@gmail.com
Backpatch-through: v12
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/backup/basebackup.c | 4 | ||||
-rw-r--r-- | src/bin/pg_basebackup/t/010_pg_basebackup.pl | 17 | ||||
-rw-r--r-- | src/bin/pg_checksums/pg_checksums.c | 4 | ||||
-rw-r--r-- | src/bin/pg_checksums/t/002_actions.pl | 7 | ||||
-rw-r--r-- | src/bin/pg_rewind/filemap.c | 4 | ||||
-rw-r--r-- | src/bin/pg_rewind/t/003_extrafiles.pl | 5 |
6 files changed, 41 insertions, 0 deletions
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c index 45be21131c5..52f0cd3be19 100644 --- a/src/backend/backup/basebackup.c +++ b/src/backend/backup/basebackup.c @@ -1202,6 +1202,10 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly, strlen(PG_TEMP_FILE_PREFIX)) == 0) continue; + /* Skip macOS system files */ + if (strcmp(de->d_name, ".DS_Store") == 0) + continue; + /* * Check if the postmaster has signaled us to exit, and abort with an * error in that case. The error handler further up will call diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index b9f5e1266b4..c8cef688d49 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -3,6 +3,7 @@ use strict; use warnings; +use Config; use File::Basename qw(basename dirname); use File::Path qw(rmtree); use PostgreSQL::Test::Cluster; @@ -179,6 +180,16 @@ foreach my $filename ( close $file; } +# Test that macOS system files are skipped. Only test on non-macOS systems +# however since creating incorrect .DS_Store files on a macOS system may have +# unintended side effects. +if ($Config{osname} ne 'darwin') +{ + open my $file, '>>', "$pgdata/.DS_Store"; + print $file "DONOTCOPY"; + close $file; +} + # Connect to a database to create global/pg_internal.init. If this is removed # the test to ensure global/pg_internal.init is not copied will return a false # positive. @@ -248,6 +259,12 @@ foreach my $filename ( ok(!-f "$tempdir/backup/$filename", "$filename not copied"); } +# We only test .DS_Store files being skipped on non-macOS systems +if ($Config{osname} ne 'darwin') +{ + ok(!-f "$tempdir/backup/.DS_Store", ".DS_Store not copied"); +} + # Unlogged relation forks other than init should not be copied ok(-f "$tempdir/backup/${baseUnloggedPath}_init", 'unlogged init fork in backup'); diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index 19eb67e4854..64b31d57d89 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -337,6 +337,10 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly) strlen(PG_TEMP_FILES_DIR)) == 0) continue; + /* Skip macOS system files */ + if (strcmp(de->d_name, ".DS_Store") == 0) + continue; + snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name); if (lstat(fn, &st) < 0) pg_fatal("could not stat file \"%s\": %m", fn); diff --git a/src/bin/pg_checksums/t/002_actions.pl b/src/bin/pg_checksums/t/002_actions.pl index 2d63182d59f..1d4d39db587 100644 --- a/src/bin/pg_checksums/t/002_actions.pl +++ b/src/bin/pg_checksums/t/002_actions.pl @@ -6,6 +6,7 @@ use strict; use warnings; +use Config; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; @@ -114,6 +115,12 @@ append_to_file "$pgdata/global/pgsql_tmp/1.1", "foo"; append_to_file "$pgdata/global/pg_internal.init", "foo"; append_to_file "$pgdata/global/pg_internal.init.123", "foo"; +# These are non-postgres macOS files, which should be ignored by the scan. +# Only perform this test on non-macOS systems though as creating incorrect +# system files may have side effects on macOS. +append_to_file "$pgdata/global/.DS_Store", "foo" + unless ($Config{osname} eq 'darwin'); + # Enable checksums. command_ok([ 'pg_checksums', '--enable', '--no-sync', '-D', $pgdata ], "checksums successfully enabled in cluster"); diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c index bd5c598e200..435742d20d1 100644 --- a/src/bin/pg_rewind/filemap.c +++ b/src/bin/pg_rewind/filemap.c @@ -647,6 +647,10 @@ decide_file_action(file_entry_t *entry) if (strcmp(path, "global/pg_control") == 0) return FILE_ACTION_NONE; + /* Skip macOS system files */ + if (strstr(path, ".DS_Store") != NULL) + return FILE_ACTION_NONE; + /* * Remove all files matching the exclusion filters in the target. */ diff --git a/src/bin/pg_rewind/t/003_extrafiles.pl b/src/bin/pg_rewind/t/003_extrafiles.pl index 2e06abb9237..b6bfc5ed808 100644 --- a/src/bin/pg_rewind/t/003_extrafiles.pl +++ b/src/bin/pg_rewind/t/003_extrafiles.pl @@ -5,6 +5,7 @@ use strict; use warnings; +use Config; use PostgreSQL::Test::Utils; use Test::More; @@ -53,6 +54,10 @@ sub run_test append_to_file "$test_standby_datadir/tst_standby_dir/standby_subdir/standby_file4", "in standby4"; + # Skip testing .DS_Store files on macOS to avoid risk of side effects + append_to_file + "$test_standby_datadir/tst_standby_dir/.DS_Store", + "macOS system file" unless ($Config{osname} eq 'darwin'); mkdir "$test_primary_datadir/tst_primary_dir"; append_to_file "$test_primary_datadir/tst_primary_dir/primary_file1", |