Skip to content

Commit 7149db1

Browse files
committed
Added t6089 - test for an internal & explicit file write ignore.
Writing to a file inside a .git directory is ok (it just generates a warning about writing to a hidden file). However, if you also explicitly ignore it with an exclusion like ^\.git, then tup checks that first and fails to find a pel pointer and returns an internal error. Instead we can do the internal checks first, and only if those pass we can check the exclusions. Fixes #468.
1 parent b037d4b commit 7149db1

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

src/tup/file.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,17 @@ static int update_write_info(FILE *f, tupid_t cmdid, struct file_info *info,
700700

701701
w = TAILQ_FIRST(&info->write_list);
702702

703+
if(get_path_elements(w->filename, &pg) < 0)
704+
return -1;
705+
if(pg.pg_flags & PG_HIDDEN) {
706+
if(warnings) {
707+
fprintf(f, "tup warning: Writing to hidden file '%s'\n", w->filename);
708+
(*warnings)++;
709+
}
710+
del_pel_group(&pg);
711+
goto out_skip;
712+
}
713+
703714
if(exclusion_match(f, &info->exclusion_root, w->filename, &match) < 0)
704715
return -1;
705716
if(match) {
@@ -719,17 +730,6 @@ static int update_write_info(FILE *f, tupid_t cmdid, struct file_info *info,
719730
}
720731
}
721732

722-
if(get_path_elements(w->filename, &pg) < 0)
723-
return -1;
724-
if(pg.pg_flags & PG_HIDDEN) {
725-
if(warnings) {
726-
fprintf(f, "tup warning: Writing to hidden file '%s'\n", w->filename);
727-
(*warnings)++;
728-
}
729-
del_pel_group(&pg);
730-
goto out_skip;
731-
}
732-
733733
tent = NULL;
734734
newdt = find_dir_tupid_dt_pg(DOT_DT, &pg, &pel, 0, 0);
735735
del_pel_group(&pg);

test/t6089-broken-update67.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /bin/sh -e
2+
# tup - A file-based build system
3+
#
4+
# Copyright (C) 2022 Mike Shal <marfey@gmail.com>
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License version 2 as
8+
# published by the Free Software Foundation.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License along
16+
# with this program; if not, write to the Free Software Foundation, Inc.,
17+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
19+
# Try writing to a file in a file that is both internally ignored (eg: in .git
20+
# from pel_ignored()) and explicitly ignored with an exclusion. Tup was
21+
# checking the explicit ignores first, and getting an internal error about not
22+
# finding the final pel pointer because the .git directory is also internally
23+
# ignored.
24+
25+
. ./tup.sh
26+
27+
mkdir .git
28+
cat > Tupfile << HERE
29+
: |> touch %o && touch .git/index-lock |> out ^\.git
30+
HERE
31+
update
32+
33+
eotup

0 commit comments

Comments
 (0)