Subject: constify arguments of copy_file() and copydir()

From: Nathan Bossart <[email-masked]>
Date: Sat, 14 Jan 2023 15:11:26 -0800

I've attached a patch for $SUBJECT, which allows us to remove a use of the
unconstify macro in basic_archive.  This is just a pet peeve, but maybe it
bothers others, too.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c
index 28cbb6cce0..3d29711a31 100644
--- a/contrib/basic_archive/basic_archive.c
+++ b/contrib/basic_archive/basic_archive.c
@@ -275,7 +275,7 @@ basic_archive_file_internal(const char *file, const char *path)
 	 * Copy the file to its temporary destination.  Note that this will fail
 	 * if temp already exists.
 	 */
-	copy_file(unconstify(char *, path), temp);
+	copy_file(path, temp);
 
 	/*
 	 * Sync the temporary file to disk and move it to its final destination.
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 7782e26677..e04bc3941a 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -34,7 +34,7 @@
  * a directory or a regular file is ignored.
  */
 void
-copydir(char *fromdir, char *todir, bool recurse)
+copydir(const char *fromdir, const char *todir, bool recurse)
 {
 	DIR		   *xldir;
 	struct dirent *xlde;
@@ -114,7 +114,7 @@ copydir(char *fromdir, char *todir, bool recurse)
  * copy one file
  */
 void
-copy_file(char *fromfile, char *tofile)
+copy_file(const char *fromfile, const char *tofile)
 {
 	char	   *buffer;
 	int			srcfd;
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
index 713b732da2..a8be5b21e0 100644
--- a/src/include/storage/copydir.h
+++ b/src/include/storage/copydir.h
@@ -13,7 +13,7 @@
 #ifndef COPYDIR_H
 #define COPYDIR_H
 
-extern void copydir(char *fromdir, char *todir, bool recurse);
-extern void copy_file(char *fromfile, char *tofile);
+extern void copydir(const char *fromdir, const char *todir, bool recurse);
+extern void copy_file(const char *fromfile, const char *tofile);
 
 #endif							/* COPYDIR_H */

---

From: Andrew Dunstan <[email-masked]>
Date: Sun, 15 Jan 2023 08:23:13 -0500

> unconstify macro in basic_archive.  This is just a pet peeve, but maybe it

I don't like using unconstify where it can be avoided, so this looks
reasonable to me.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

---

From: Nathan Bossart <[email-masked]>
Date: Sun, 15 Jan 2023 08:13:28 -0800

> I don't like using unconstify where it can be avoided, so this looks

Thanks.  Added to the next commitfest:

	https://commitfest.postgresql.org/42/4126/

---

From: Michael Paquier <[email-masked]>
Date: Mon, 16 Jan 2023 10:53:40 +0900

>> I don't like using unconstify where it can be avoided, so this looks

+1.
--
Michael

---

From: Michael Paquier <[email-masked]>
Date: Tue, 17 Jan 2023 15:24:54 +0900

While I don't forget about this thread..  Any objections if I were to
apply that?
--
Michael

---

From: Peter Eisentraut <[email-masked]>
Date: Tue, 17 Jan 2023 20:23:49 +0100

> While I don't forget about this thread..  Any objections if I were to

Looks good to me.

---

From: Michael Paquier <[email-masked]>
Date: Wed, 18 Jan 2023 09:05:52 +0900

> Looks good to me.

Thanks, done.
--
Michael

---

From: Nathan Bossart <[email-masked]>
Date: Tue, 17 Jan 2023 16:08:02 -0800

> Thanks, done.

Thanks!