Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c1fc502

Browse files
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
1 parent e4b88c5 commit c1fc502

File tree

9 files changed

+47
-4
lines changed

9 files changed

+47
-4
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
31273127
<para>
31283128
Files other than regular files and directories, such as symbolic
31293129
links (other than for the directories listed above) and special
3130-
device files, are skipped. (Symbolic links
3130+
device and operating system files, are skipped. (Symbolic links
31313131
in <filename>pg_tblspc</filename> are maintained.)
31323132
</para>
31333133
</listitem>

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ PostgreSQL documentation
965965
The backup will include all files in the data directory and tablespaces,
966966
including the configuration files and any additional files placed in the
967967
directory by third parties, except certain temporary files managed by
968-
PostgreSQL. But only regular files and directories are copied, except that
968+
PostgreSQL and operating system files. But only regular files and
969+
directories are copied, except that
969970
symbolic links used for tablespaces are preserved. Symbolic links pointing
970971
to certain directories known to PostgreSQL are copied as empty directories.
971972
Other symbolic links and special device files are skipped.

doc/src/sgml/ref/pg_rewind.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, b
403403
<filename>backup_label</filename>,
404404
<filename>tablespace_map</filename>,
405405
<filename>pg_internal.init</filename>,
406-
<filename>postmaster.opts</filename>, and
407-
<filename>postmaster.pid</filename>, as well as any file or directory
406+
<filename>postmaster.opts</filename>,
407+
<filename>postmaster.pid</filename> and
408+
<filename>.DS_Store</filename> as well as any file or directory
408409
beginning with <filename>pgsql_tmp</filename>, are omitted.
409410
</para>
410411
</step>

src/backend/backup/basebackup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,10 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
12651265
strlen(PG_TEMP_FILE_PREFIX)) == 0)
12661266
continue;
12671267

1268+
/* Skip macOS system files */
1269+
if (strcmp(de->d_name, ".DS_Store") == 0)
1270+
continue;
1271+
12681272
/*
12691273
* Check if the postmaster has signaled us to exit, and abort with an
12701274
* error in that case. The error handler further up will call

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use strict;
55
use warnings FATAL => 'all';
6+
use Config;
67
use File::Basename qw(basename dirname);
78
use File::Path qw(rmtree);
89
use PostgreSQL::Test::Cluster;
@@ -179,6 +180,16 @@
179180
close $file;
180181
}
181182

183+
# Test that macOS system files are skipped. Only test on non-macOS systems
184+
# however since creating incorrect .DS_Store files on a macOS system may have
185+
# unintended side effects.
186+
if ($Config{osname} ne 'darwin')
187+
{
188+
open my $file, '>>', "$pgdata/.DS_Store";
189+
print $file "DONOTCOPY";
190+
close $file;
191+
}
192+
182193
# Connect to a database to create global/pg_internal.init. If this is removed
183194
# the test to ensure global/pg_internal.init is not copied will return a false
184195
# positive.
@@ -248,6 +259,12 @@
248259
ok(!-f "$tempdir/backup/$filename", "$filename not copied");
249260
}
250261

262+
# We only test .DS_Store files being skipped on non-macOS systems
263+
if ($Config{osname} ne 'darwin')
264+
{
265+
ok(!-f "$tempdir/backup/.DS_Store", ".DS_Store not copied");
266+
}
267+
251268
# Unlogged relation forks other than init should not be copied
252269
ok(-f "$tempdir/backup/${baseUnloggedPath}_init",
253270
'unlogged init fork in backup');

src/bin/pg_checksums/pg_checksums.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
329329
strlen(PG_TEMP_FILES_DIR)) == 0)
330330
continue;
331331

332+
/* Skip macOS system files */
333+
if (strcmp(de->d_name, ".DS_Store") == 0)
334+
continue;
335+
332336
snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
333337
if (lstat(fn, &st) < 0)
334338
pg_fatal("could not stat file \"%s\": %m", fn);

src/bin/pg_checksums/t/002_actions.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use strict;
88
use warnings FATAL => 'all';
9+
use Config;
910
use PostgreSQL::Test::Cluster;
1011
use PostgreSQL::Test::Utils;
1112

@@ -114,6 +115,12 @@ sub check_relation_corruption
114115
append_to_file "$pgdata/global/pg_internal.init", "foo";
115116
append_to_file "$pgdata/global/pg_internal.init.123", "foo";
116117

118+
# These are non-postgres macOS files, which should be ignored by the scan.
119+
# Only perform this test on non-macOS systems though as creating incorrect
120+
# system files may have side effects on macOS.
121+
append_to_file "$pgdata/global/.DS_Store", "foo"
122+
unless ($Config{osname} eq 'darwin');
123+
117124
# Enable checksums.
118125
command_ok([ 'pg_checksums', '--enable', '--no-sync', '-D', $pgdata ],
119126
"checksums successfully enabled in cluster");

src/bin/pg_rewind/filemap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ decide_file_action(file_entry_t *entry)
647647
if (strcmp(path, "global/pg_control") == 0)
648648
return FILE_ACTION_NONE;
649649

650+
/* Skip macOS system files */
651+
if (strstr(path, ".DS_Store") != NULL)
652+
return FILE_ACTION_NONE;
653+
650654
/*
651655
* Remove all files matching the exclusion filters in the target.
652656
*/

src/bin/pg_rewind/t/003_extrafiles.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use strict;
77
use warnings FATAL => 'all';
8+
use Config;
89
use PostgreSQL::Test::Utils;
910
use Test::More;
1011

@@ -53,6 +54,10 @@ sub run_test
5354
append_to_file
5455
"$test_standby_datadir/tst_standby_dir/standby_subdir/standby_file4",
5556
"in standby4";
57+
# Skip testing .DS_Store files on macOS to avoid risk of side effects
58+
append_to_file
59+
"$test_standby_datadir/tst_standby_dir/.DS_Store",
60+
"macOS system file" unless ($Config{osname} eq 'darwin');
5661

5762
mkdir "$test_primary_datadir/tst_primary_dir";
5863
append_to_file "$test_primary_datadir/tst_primary_dir/primary_file1",

0 commit comments

Comments
 (0)