v6-0001-Skip-.DS_Store-files-in-server-side-utils.patch
application/octet-stream
Filename: v6-0001-Skip-.DS_Store-files-in-server-side-utils.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v6-0001
Subject: Skip .DS_Store files in server side utils
| File | + | − |
|---|---|---|
| doc/src/sgml/protocol.sgml | 1 | 1 |
| doc/src/sgml/ref/pg_basebackup.sgml | 2 | 1 |
| doc/src/sgml/ref/pg_rewind.sgml | 3 | 2 |
| src/backend/backup/basebackup.c | 4 | 0 |
| src/bin/pg_basebackup/t/010_pg_basebackup.pl | 17 | 0 |
| src/bin/pg_checksums/pg_checksums.c | 4 | 0 |
| src/bin/pg_checksums/t/002_actions.pl | 7 | 0 |
| src/bin/pg_rewind/file_ops.c | 4 | 0 |
From b9128e948fb85505f5bdbc097ea9c972c837ce8b Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <dgustafsson@postgresql.org>
Date: Thu, 20 Jul 2023 00:39:39 +0200
Subject: [PATCH v6] 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.
Reported-by: Mark Guertin <markguertin@gmail.com>
Discussion: https://postgr.es/m/E258CE50-AB0E-455D-8AAD-BB4FE8F882FB@gmail.com
---
doc/src/sgml/protocol.sgml | 2 +-
doc/src/sgml/ref/pg_basebackup.sgml | 3 ++-
doc/src/sgml/ref/pg_rewind.sgml | 5 +++--
src/backend/backup/basebackup.c | 4 ++++
src/bin/pg_basebackup/t/010_pg_basebackup.pl | 17 +++++++++++++++++
src/bin/pg_checksums/pg_checksums.c | 4 ++++
src/bin/pg_checksums/t/002_actions.pl | 7 +++++++
src/bin/pg_rewind/file_ops.c | 4 ++++
8 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index b11d9a6ba3..d8765100e3 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -3049,7 +3049,7 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
<para>
Files other than regular files and directories, such as symbolic
links (other than for the directories listed above) and special
- device files, are skipped. (Symbolic links
+ device and operating system files, are skipped. (Symbolic links
in <filename>pg_tblspc</filename> are maintained.)
</para>
</listitem>
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml
index 79d3e657c3..c2fd27ca64 100644
--- a/doc/src/sgml/ref/pg_basebackup.sgml
+++ b/doc/src/sgml/ref/pg_basebackup.sgml
@@ -909,7 +909,8 @@ PostgreSQL documentation
The backup will include all files in the data directory and tablespaces,
including the configuration files and any additional files placed in the
directory by third parties, except certain temporary files managed by
- PostgreSQL. But only regular files and directories are copied, except that
+ PostgreSQL and operating system files. But only regular files and
+ directories are copied, except that
symbolic links used for tablespaces are preserved. Symbolic links pointing
to certain directories known to PostgreSQL are copied as empty directories.
Other symbolic links and special device files are skipped.
diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml
index 15cddd086b..2de747ec37 100644
--- a/doc/src/sgml/ref/pg_rewind.sgml
+++ b/doc/src/sgml/ref/pg_rewind.sgml
@@ -381,8 +381,9 @@ GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, b
<filename>backup_label</filename>,
<filename>tablespace_map</filename>,
<filename>pg_internal.init</filename>,
- <filename>postmaster.opts</filename>, and
- <filename>postmaster.pid</filename>, as well as any file or directory
+ <filename>postmaster.opts</filename>,
+ <filename>postmaster.pid</filename> and
+ <filename>.DS_Store</filename> as well as any file or directory
beginning with <filename>pgsql_tmp</filename>, are omitted.
</para>
</step>
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 45be21131c..52f0cd3be1 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 b9f5e1266b..c8cef688d4 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 19eb67e485..64b31d57d8 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 2d63182d59..1d4d39db58 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/file_ops.c b/src/bin/pg_rewind/file_ops.c
index 25996b4da4..f7a2abb48e 100644
--- a/src/bin/pg_rewind/file_ops.c
+++ b/src/bin/pg_rewind/file_ops.c
@@ -398,6 +398,10 @@ recurse_dir(const char *datadir, const char *parentpath,
strcmp(xlde->d_name, "..") == 0)
continue;
+ /* Skip macOS system files */
+ if (strcmp(xlde->d_name, ".DS_Store") == 0)
+ continue;
+
snprintf(fullpath, sizeof(fullpath), "%s/%s", fullparentpath, xlde->d_name);
if (lstat(fullpath, &fst) < 0)
--
2.32.1 (Apple Git-133)