From 0172e14c26ec4702e956ec99e6158a4bd64d4540 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Tue, 7 Jan 2014 18:57:38 +0100
Subject: [PATCH] lib-sieve: Changed sieve_script_binary_get_directory() to
 sieve_script_binary_get_prefix(). This function now returns the binary prefix
 (file path until '.svbin) rather than just the path of the directory where
 the binary would be stored.

---
 src/lib-sieve/sieve-script-file.c    | 16 +++++++++++-----
 src/lib-sieve/sieve-script-private.h |  3 ++-
 src/lib-sieve/sieve-script.c         |  8 ++++----
 src/lib-sieve/sieve-script.h         |  2 +-
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/lib-sieve/sieve-script-file.c b/src/lib-sieve/sieve-script-file.c
index 3808750a9..8708878c6 100644
--- a/src/lib-sieve/sieve-script-file.c
+++ b/src/lib-sieve/sieve-script-file.c
@@ -122,7 +122,7 @@ static int sieve_file_script_open
 	struct sieve_error_handler *ehandler = _script->ehandler;
 	pool_t pool = _script->pool;
 	const char *name = _script->name;
-	const char *filename, *dirpath, *basename, *binpath;
+	const char *filename, *dirpath, *basename, *binpath, *binprefix;
 	struct stat st;
 	struct stat lnk_st;
 	bool success = TRUE;
@@ -220,10 +220,15 @@ static int sieve_file_script_open
 			if ( _script->bin_dir != NULL ) {
 				binpath = sieve_binfile_from_name(name);
 				binpath = t_strconcat(_script->bin_dir, "/", binpath, NULL);
+				binprefix = t_strconcat(_script->bin_dir, "/", name, NULL);
 			} else {
 				binpath = sieve_binfile_from_name(basename);
-				if ( *dirpath != '\0' )
+				if ( *dirpath != '\0' ) {
 					binpath = t_strconcat(dirpath, "/", binpath, NULL);
+					binprefix = t_strconcat(dirpath, "/", basename, NULL);
+				} else {
+					binprefix = basename;
+				}
 			}
 
 			script->st = st;
@@ -232,6 +237,7 @@ static int sieve_file_script_open
 			script->filename = p_strdup(pool, filename);
 			script->dirpath = p_strdup(pool, dirpath);
 			script->binpath = p_strdup(pool, binpath);
+			script->binprefix = p_strdup(pool, binprefix);
 
 			if ( script->script.name == NULL ||
 				strcmp(script->script.name, basename) == 0 )
@@ -354,12 +360,12 @@ static int sieve_file_script_binary_save
 		script->st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO), error_r);
 }
 
-static const char *sieve_file_script_binary_get_directory
+static const char *sieve_file_script_binary_get_prefix
 (struct sieve_script *_script)
 {
 	struct sieve_file_script *script = (struct sieve_file_script *)_script;
 	
-	return script->	dirpath;
+	return script->	binprefix;
 }
 
 const struct sieve_script sieve_file_script = {
@@ -376,7 +382,7 @@ const struct sieve_script sieve_file_script = {
 		NULL,
 		sieve_file_script_binary_load,
 		sieve_file_script_binary_save,
-		sieve_file_script_binary_get_directory,
+		sieve_file_script_binary_get_prefix,
 
 		sieve_file_script_get_size,
 
diff --git a/src/lib-sieve/sieve-script-private.h b/src/lib-sieve/sieve-script-private.h
index 3a0797b78..174cff3cd 100644
--- a/src/lib-sieve/sieve-script-private.h
+++ b/src/lib-sieve/sieve-script-private.h
@@ -32,7 +32,7 @@ struct sieve_script_vfuncs {
 	int (*binary_save)
 		(struct sieve_script *script, struct sieve_binary *sbin,
 			bool update, enum sieve_error *error_r);
-	const char *(*binary_get_directory)
+	const char *(*binary_get_prefix)
 		(struct sieve_script *script);
 
 	int (*get_size)
@@ -88,6 +88,7 @@ struct sieve_file_script {
 	const char *dirpath;
 	const char *filename;
 	const char *binpath;
+	const char *binprefix;
 
 	int fd;
 };
diff --git a/src/lib-sieve/sieve-script.c b/src/lib-sieve/sieve-script.c
index 9afc073af..9e56951e0 100644
--- a/src/lib-sieve/sieve-script.c
+++ b/src/lib-sieve/sieve-script.c
@@ -542,18 +542,18 @@ int sieve_script_binary_save
 	return script->v.binary_save(script, sbin, update, error_r);
 }
 
-const char *sieve_script_binary_get_directory
+const char *sieve_script_binary_get_prefix
 (struct sieve_script *script)
 {
 	if ( script->bin_dir != NULL &&
 		sieve_script_setup_bindir(script, 0700) >= 0 ) {
-		return script->bin_dir;
+		return t_strconcat(script->bin_dir, "/", script->name, NULL);
 	}
 
-	if ( script->v.binary_get_directory == NULL )
+	if ( script->v.binary_get_prefix == NULL )
 		return NULL;
 
-	return script->v.binary_get_directory(script);
+	return script->v.binary_get_prefix(script);
 }
 
 int sieve_script_setup_bindir
diff --git a/src/lib-sieve/sieve-script.h b/src/lib-sieve/sieve-script.h
index 9889aa0c1..b5cbc5482 100644
--- a/src/lib-sieve/sieve-script.h
+++ b/src/lib-sieve/sieve-script.h
@@ -68,7 +68,7 @@ int sieve_script_binary_save
 	(struct sieve_script *script, struct sieve_binary *sbin, bool update,
 		enum sieve_error *error_r);
 
-const char *sieve_script_binary_get_directory
+const char *sieve_script_binary_get_prefix
 	(struct sieve_script *script);
 
 /*
-- 
GitLab