From f9b57ab287f585d3ec0a196af5e05e00fe23f6eb Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 12 Mar 2014 16:41:43 -0400 Subject: [PATCH] Fix: return error if not in overwrite mode and file exists For the save command, if the file is found and we are not in overwrite mode, send back an new error indicating the client that the file already exists. Fixes #762 Signed-off-by: David Goulet --- include/lttng/lttng-error.h | 2 +- src/bin/lttng-sessiond/save.c | 3 ++- src/common/error.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 87b6f84d6..d3f71880f 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -115,7 +115,7 @@ enum lttng_error_code { LTTNG_ERR_KERN_EVENT_ENOSYS = 82, /* Kernel event type not supported */ LTTNG_ERR_NEED_CHANNEL_NAME = 83, /* Non-default channel exists within session: channel name needs to be specified with '-c name' */ LTTNG_ERR_NO_UST = 84, /* LTTng-UST tracer is not supported. Please rebuild lttng-tools with lttng-ust support enabled. */ - /* 85 */ + LTTNG_ERR_SAVE_FILE_EXIST = 85, /* Session file already exists. */ /* 86 */ /* 87 */ /* 88 */ diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index fd6c5d894..fe5461cb1 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1478,7 +1478,8 @@ int save_session(struct ltt_session *session, config_file_path[len] = '\0'; if (!access(config_file_path, F_OK) && !attr->overwrite) { - /* A file with the same name already exists, skip */ + /* File exists, notify the user since the overwrite flag is off. */ + ret = LTTNG_ERR_SAVE_FILE_EXIST; goto end; } diff --git a/src/common/error.c b/src/common/error.c index 53b55b93f..b66c12d94 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -117,6 +117,7 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_NODATA) ] = "No data available in snapshot", [ ERROR_INDEX(LTTNG_ERR_NO_CHANNEL) ] = "No channel found in the session", [ ERROR_INDEX(LTTNG_ERR_SESSION_INVALID_CHAR) ] = "Invalid character found in session name", + [ ERROR_INDEX(LTTNG_ERR_SAVE_FILE_EXIST) ] = "Session file already exists", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code" -- 2.34.1