Skip to content

Commit 2ad1274

Browse files
authored
Merge pull request #4085 from masatake/main--tags-dir
main: error with more friendly and understandable message when "tags" directory exists
2 parents 3e7d5eb + bf78faa commit 2ad1274

File tree

8 files changed

+27
-0
lines changed

8 files changed

+27
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright: 2024 Masatake YAMATO
2+
# License: GPL-2
3+
4+
CTAGS=$1
5+
6+
${CTAGS} --quiet --options=NONE $0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ctags: "tags" already exists as a directory; I cannot write tag entries there.
2+
Remove the directory or specify a file name with -o <tagfile> option.

Tmain/errors-if-tags-exits-as-directory.d/stdout-expected.txt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

main/entry.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,17 @@ extern void openTagFile (void)
422422
else
423423
{
424424
bool fileExists;
425+
bool directoryExists;
425426

426427
TagFile.name = eStrdup (Option.tagFileName);
428+
429+
directoryExists = doesDirectoryExist (TagFile.name);
430+
if (directoryExists)
431+
error (FATAL,
432+
"\"%s\" already exists as a directory; I cannot write tag entries there.\n"
433+
"Remove the directory or specify a file name with -o <tagfile> option.",
434+
TagFile.name);
435+
427436
fileExists = doesFileExist (TagFile.name);
428437
if (fileExists && ! isTagFile (TagFile.name))
429438
error (FATAL,

main/routines.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ extern void eStatFree (fileStatus *status)
480480
}
481481
}
482482

483+
extern bool doesDirectoryExist (const char *const fileName)
484+
{
485+
fileStatus *status = eStat (fileName);
486+
return status->exists && status->isDirectory;
487+
}
488+
483489
extern bool doesFileExist (const char *const fileName)
484490
{
485491
fileStatus *status = eStat (fileName);

main/routines_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern void setCurrentDirectory (void);
8686
extern fileStatus *eStat (const char *const fileName);
8787
extern void eStatFree (fileStatus *status);
8888
extern bool doesFileExist (const char *const fileName);
89+
extern bool doesDirectoryExist (const char *const fileName);
8990
extern bool doesExecutableExist (const char *const fileName);
9091
extern bool isRecursiveLink (const char* const dirName);
9192
extern bool isSameFile (const char *const name1, const char *const name2);

0 commit comments

Comments
 (0)