From d67b858d0254e3252f0a63270d2621317c512127 Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Mon, 26 Dec 2022 18:26:28 +0100
Subject: [PATCH] Copy missing files if --copy given but a link exists (bug
33573)
---
bin/automake.in | 4 ++--
t/list-of-tests.mk | 1 +
t/missing-link-to-file.sh | 42 +++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 2 deletions(-)
create mode 100644 t/missing-link-to-file.sh
diff --git a/bin/automake.in b/bin/automake.in
index c094234bc..dc4717f0f 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -7647,7 +7647,7 @@ sub required_file_check_or_copy
# '--force-missing' only has an effect if '--add-missing' is
# specified.
return
- if $found_it && (! $add_missing || ! $force_missing);
+ if $found_it && (! $add_missing || (! $force_missing && ! ($copy_missing && -l $fullfile)));
# If we've already looked for it, we're done. You might wonder why we
# don't do this before searching for the file. If we do that, then
@@ -7693,7 +7693,7 @@ sub required_file_check_or_copy
# Windows Perl will hang if we try to delete a
# file that doesn't exist.
- unlink ($fullfile) if -f $fullfile;
+ unlink ($fullfile) if (-f $fullfile or -l $fullfile);
if ($symlink_exists && ! $copy_missing)
{
if (! symlink ("$libdir/$file", $fullfile)
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index d82cf9c4d..395c8689a 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -712,6 +712,7 @@ t/mdate3.sh \
t/mdate4.sh \
t/mdate5.sh \
t/mdate6.sh \
+t/missing-link-to-file.sh \
t/missing-version-mismatch.sh \
t/missing3.sh \
t/am-missing-prog.sh \
diff --git a/t/missing-link-to-file.sh b/t/missing-link-to-file.sh
new file mode 100644
index 000000000..23d6d2cde
--- /dev/null
+++ b/t/missing-link-to-file.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+# Copyright (C) 2002-2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+# Make sure Automake will install real files when --copy is given even
+# if symlinks already exist.
+
+. test-init.sh
+
+cat >> configure.ac < Makefile.am << 'END'
+info_TEXINFOS = foo.texi
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+#ls -l
+
+$AUTOMAKE --add-missing --copy
+
+#ls -l
+
+test ! -h texinfo.tex || exit 1
+
+:
--
2.35.1