Commit f2c2471389048b8f930ed945ed1acfe004f901a4

nulltoken 2011-01-26T20:29:06

Made path prettifying functions return GIT_EINVALIDPATH instead of GIT_ERROR.

diff --git a/src/errors.c b/src/errors.c
index df8b822..41c4a8d 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -19,6 +19,7 @@ static struct {
 	{GIT_EFLOCKFAIL, "Failed to adquire or release a file lock"},
 	{GIT_EZLIB, "The Z library failed to inflate/deflate an object's data"},
 	{GIT_EBUSY, "The queried object is currently busy"},
+	{GIT_EINVALIDPATH, "The path is invalid"},
 };
 
 const char *git_strerror(int num)
diff --git a/src/fileops.c b/src/fileops.c
index c2668c5..461dcf0 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -438,7 +438,7 @@ int gitfo_prettify_dir_path(char *buffer_out, const char *path)
 			*buffer_out ='\0';
 			len = retrieve_previous_path_component_start(buffer_out_start);
 			if (len < GIT_SUCCESS)
-				return GIT_ERROR;
+				return GIT_EINVALIDPATH;
 
 			buffer_out = (char *)buffer_out_start + len;
 			continue;
@@ -446,7 +446,7 @@ int gitfo_prettify_dir_path(char *buffer_out, const char *path)
 
 		/* Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html) */
 		if (only_dots &&segment_len > 0)
-			return GIT_ERROR;
+			return GIT_EINVALIDPATH;
 
 		*buffer_out++ = '/';
 		len++;
@@ -467,7 +467,7 @@ int gitfo_prettify_file_path(char *buffer_out, const char *path)
 	/* Let's make sure the filename doesn't end with "/", "/." or "/.." */
 	for (i = 1; path_len > i && i < 4; i++) {
 		if (!strncmp(path + path_len - i, pattern, i))
-			return GIT_ERROR;
+			return GIT_EINVALIDPATH;
 	}
 
 	error =  gitfo_prettify_dir_path(buffer_out, path);
@@ -476,7 +476,7 @@ int gitfo_prettify_file_path(char *buffer_out, const char *path)
 
 	path_len = strlen(buffer_out);
 	if (path_len < 2)
-		return GIT_ERROR;
+		return GIT_EINVALIDPATH;
 
 	/* Remove the trailing slash */
 	buffer_out[path_len - 1] = '\0';
diff --git a/src/git2/common.h b/src/git2/common.h
index bbeec41..350429f 100644
--- a/src/git2/common.h
+++ b/src/git2/common.h
@@ -136,6 +136,9 @@
 /** The index file is not backed up by an existing repository */
 #define GIT_EBAREINDEX (GIT_ERROR -14)
 
+/** The path is invalid */
+#define GIT_EINVALIDPATH (GIT_ERROR - 19)
+
 GIT_BEGIN_DECL
 /** @} */
 GIT_END_DECL