[Debtags-commits] [svn] r1563 - in tagcoll/trunk: . tools

Enrico Zini enrico at costa.debian.org
Sat Feb 11 12:25:10 UTC 2006


Author: enrico
Date: Sat Feb 11 12:25:07 2006
New Revision: 1563

Modified:
   tagcoll/trunk/   (props changed)
   tagcoll/trunk/tools/tagidx.cc
Log:
 r7217 at viaza:  enrico | 2006-02-10 16:31:02 +0100
 Added mkpath to tagidx


Modified: tagcoll/trunk/tools/tagidx.cc
==============================================================================
--- tagcoll/trunk/tools/tagidx.cc	(original)
+++ tagcoll/trunk/tools/tagidx.cc	Sat Feb 11 12:25:07 2006
@@ -37,12 +37,21 @@
 #include "CommandlineParser.h"
 #include "Index.h"
 
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <errno.h>
+
+#include <tagcoll/StdioParserInput.h>
+#include <tagcoll/TextFormat.h>
+
+#include <iostream>
+
 #if 0
 #include <stdio.h>
 
 #include <stdlib.h>	// getenv
 
-#include <errno.h>
 
 #include <tagcoll/stringf.h>
 #include <tagcoll/Exception.h>
@@ -59,8 +68,6 @@
 #include <tagcoll/DerivedTags.h>
 #include <tagcoll/ItemGrouper.h>
 
-#include <tagcoll/StdioParserInput.h>
-#include <tagcoll/TextFormat.h>
 #include <tagcoll/Serializer.h>
 #include <tagcoll/Expression.h>
 
@@ -110,6 +117,7 @@
 
 	return items;
 }
+#endif
 
 void readCollection(const string& file, Consumer<string, string>& builder)
 	throw (FileException, ParserException)
@@ -128,6 +136,7 @@
 	}
 }
 
+#if 0
 PatchList<string, string> readPatches(const string& file)
 	throw (FileException, ParserException)
 {
@@ -453,12 +462,36 @@
 		return opts.get("index").stringVal();
 	if (getenv("TAGIDX") != NULL)
 		return getenv("TAGIDX");
-	struct passwd* pw getpwuid(getuid());
+	struct passwd* pw = getpwuid(getuid());
 	if (pw != NULL)
 		return string(pw->pw_dir) + "/.tagcoll/index";
 	throw NotFoundException("looking for a suitable place for the index directory (tried the --index commandline option, the $TAGIDX environment variable and the home directory)");
 }
 
+void mkpath(const std::string& dir)
+{
+	size_t sep = dir.rfind('/');
+
+	//cerr << "Ensuring existance of " << dir << endl;
+
+	// First ensure that the parent directory exists
+	if (sep != string::npos && sep != 0)
+		mkpath(dir.substr(0, sep));
+
+	// Then create this directory if needed
+	struct stat st;
+	if (stat(dir.c_str(), &st) == -1)
+	{
+		if (errno == ENOENT)
+		{
+			if (mkdir(dir.c_str(), 0777) == -1)
+				throw SystemException(errno, "creating directory " + dir);
+		} else
+			throw SystemException(errno, "getting informations about " + dir);
+	} else if (!S_ISDIR(st.st_mode))
+		throw ConsistencyCheckException("ensuring that " + dir + " is a directory");
+}
+
 int main(int argc, const char* argv[])
 {
 	try {



More information about the Debtags-commits mailing list