return NT_STATUS_OK;
}
+/*
+ * Determine the snapper snapshot id given a path.
+ * Ideally this should be determined via a lookup.
+ */
+static NTSTATUS snapper_snap_path_to_id(TALLOC_CTX *mem_ctx,
+ const char *snap_path,
+ uint32_t *snap_id_out)
+{
+ char *path_dup;
+ char *str_idx;
+ char *str_end;
+ uint32_t snap_id;
+
+ path_dup = talloc_strdup(mem_ctx, snap_path);
+ if (path_dup == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* trim trailing '/' */
+ str_idx = path_dup + strlen(path_dup) - 1;
+ while (*str_idx == '/') {
+ *str_idx = '\0';
+ str_idx--;
+ }
+
+ str_idx = strrchr(path_dup, '/');
+ if ((str_idx == NULL)
+ || (strcmp(str_idx + 1, "snapshot") != 0)) {
+ talloc_free(path_dup);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ while (*str_idx == '/') {
+ *str_idx = '\0';
+ str_idx--;
+ }
+
+ str_idx = strrchr(path_dup, '/');
+ if (str_idx == NULL) {
+ talloc_free(path_dup);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ str_idx++;
+ snap_id = strtoul(str_idx, &str_end, 10);
+ if (str_idx == str_end) {
+ talloc_free(path_dup);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ talloc_free(path_dup);
+ *snap_id_out = snap_id;
+ return NT_STATUS_OK;
+}
+
+/*
+ * Determine the snapper snapshot path given an id and base.
+ * Ideally this should be determined via a lookup.
+ */
+static NTSTATUS snapper_snap_id_to_path(TALLOC_CTX *mem_ctx,
+ const char *base_path,
+ uint32_t snap_id,
+ char **snap_path_out)
+{
+ char *snap_path;
+
+ snap_path = talloc_asprintf(mem_ctx, "%s/.snapshots/%u/snapshot",
+ base_path, snap_id);
+ if (snap_path == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *snap_path_out = snap_path;
+ return NT_STATUS_OK;
+}
+
static NTSTATUS snapper_get_conf_call(TALLOC_CTX *mem_ctx,
DBusConnection *dconn,
const char *path,
goto err_rsp_free;
}
+ status = snapper_snap_id_to_path(mem_ctx, base_path, snap_id,
+ &snap_path);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto err_rsp_free;
+ }
+
dbus_message_unref(rsp_msg);
dbus_message_unref(req_msg);
- DEBUG(6, ("created new snapshot %u\n", snap_id));
-
- /*
- * Assume snapshot exists in the .snapshots subdir of the base.
- * TODO lookup via GetSnapshot
- */
- snap_path = talloc_asprintf(mem_ctx, "%s/.snapshots/%u", base_path, snap_id);
- if (snap_path == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto err_rsp_free;
- }
+ DEBUG(6, ("created new snapshot %u at %s\n", snap_id, snap_path));
*snap_path_out = snap_path;
return NT_STATUS_OK;
DBusConnection *dconn;
struct snapper_snap_delete_state *delete_state;
NTSTATUS status;
- char *snap_id_str;
- char *str_end;
req = tevent_req_create(mem_ctx, &delete_state,
struct snapper_snap_delete_state);
return tevent_req_post(req, ev);
}
- /* TODO we should look this up by doing a list_snapshots */
- snap_id_str = strrchr(snap_path, '/');
- if (snap_id_str == NULL) {
- tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
- dbus_connection_unref(dconn);
- return tevent_req_post(req, ev);
- }
- snap_id_str++;
- delete_state->snap_id = strtoul(snap_id_str, &str_end, 10);
- if (snap_id_str == str_end) {
- tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ status = snapper_snap_path_to_id(delete_state, snap_path,
+ &delete_state->snap_id);
+ if (tevent_req_nterror(req, status)) {
dbus_connection_unref(dconn);
return tevent_req_post(req, ev);
}