Constify the arguments of copydir.h functions
authorMichael Paquier <[email protected]>
Tue, 17 Jan 2023 23:55:26 +0000 (08:55 +0900)
committerMichael Paquier <[email protected]>
Tue, 17 Jan 2023 23:55:26 +0000 (08:55 +0900)
This makes sure that the internal logic of these functions does not
attempt to change the value of the arguments constified, and it removes
one unconstify() in basic_archive.c.

Author: Nathan Bossart
Reviewed-by: Andrew Dunstan, Peter Eisentraut
Discussion: https://postgr.es/m/20230114231126.GA2580330@nathanxps13

contrib/basic_archive/basic_archive.c
src/backend/storage/file/copydir.c
src/include/storage/copydir.h

index 28cbb6cce0e5e02b4cad1e30741006003190b822..3d29711a316dd9e97f388d87d0e19847cd48406e 100644 (file)
@@ -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.
index 7782e266772279926364a7914d3926bf9d5aa534..e04bc3941ae247d1e6fdb4c98a6ca07bde09097d 100644 (file)
@@ -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;
index 713b732da23e2d926b7fd37ee60f45fe0cfb96c9..a8be5b21e0b2eaf6f33211a985ccd40a68ce3707 100644 (file)
@@ -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 */