Commit 03df25b334950c4fa76dc9a86b3df050861298ce

Stefan Sperling 2019-05-11T19:13:10

disallow directories with 'got add'; add a TODO item for them

diff --git a/TODO b/TODO
index cc9cceb..e957e0f 100644
--- a/TODO
+++ b/TODO
@@ -2,6 +2,7 @@ lib:
 - handle checkout of trees which contain submodules by identifying and
   ignoring such tree entries; requires a .ini config parser (from isakmpd?)
 - allow removing multiple paths at once for 'got rm'
+- allow adding directory paths with 'got add'
 - recursive addition: got add -R
 - recursive removal: got rm -R
 
diff --git a/lib/fileindex.c b/lib/fileindex.c
index a868d40..61562ca 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -18,6 +18,7 @@
 #include <sys/tree.h>
 #include <sys/stat.h>
 
+#include <errno.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -60,8 +61,12 @@ got_fileindex_entry_update(struct got_fileindex_entry *entry,
 	if (lstat(ondisk_path, &sb) != 0) {
 		if ((entry->flags & GOT_FILEIDX_F_NO_FILE_ON_DISK) == 0)
 			return got_error_prefix_errno2("lstat", ondisk_path);
-	} else
+	} else {
+		if (sb.st_mode & S_IFDIR)
+			return got_error_set_errno(EISDIR, ondisk_path);
 		entry->flags &= ~GOT_FILEIDX_F_NO_FILE_ON_DISK;
+	}
+
 
 	if ((entry->flags & GOT_FILEIDX_F_NO_FILE_ON_DISK) == 0) {
 		if (update_timestamps) {