diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-02-24 14:38:10 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-03-06 16:22:15 +0100 |
commit | 99222bc472d3a42e948532425dcffb4caa72911b (patch) | |
tree | 977f5c03497eba5dc7c01e9fe350c9c2d82e856e | |
parent | fef8f6a36f7cd7d027a358e8b2f64f76f03827c1 (diff) | |
download | vd_agent-99222bc472d3a42e948532425dcffb4caa72911b.tar.gz vd_agent-99222bc472d3a42e948532425dcffb4caa72911b.tar.xz vd_agent-99222bc472d3a42e948532425dcffb4caa72911b.zip |
file-xfers: Create dir before trying to create the file
This is necesarry to allow the client to send folder-hierarchies.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/vdagent-file-xfers.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/vdagent-file-xfers.c b/src/vdagent-file-xfers.c index de38eca..898b77f 100644 --- a/src/vdagent-file-xfers.c +++ b/src/vdagent-file-xfers.c @@ -155,7 +155,7 @@ void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers, VDAgentFileXferStartMessage *msg) { AgentFileXferTask *task; - char *path = NULL, *file_path = NULL; + char *dir = NULL, *path = NULL, *file_path = NULL; const gchar *desktop; struct stat st; int i; @@ -176,14 +176,19 @@ void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers, if (desktop == NULL) { goto error; } - file_path = g_build_filename(desktop, task->file_name, NULL); + + dir = g_path_get_dirname(file_path); + if (g_mkdir_with_parents(dir, S_IRWXU) == -1) { + syslog(LOG_ERR, "file-xfer: Failed to create dir %s", dir); + goto error; + } + path = g_strdup(file_path); for (i = 0; i < 64 && (stat(path, &st) == 0 || errno != ENOENT); i++) { g_free(path); path = g_strdup_printf("%s (%d)", file_path, i + 1); } - g_free(file_path); if (i == 64) { syslog(LOG_ERR, "file-xfer: more then 63 copies of %s exist?", task->file_name); @@ -211,7 +216,9 @@ void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers, udscs_write(xfers->vdagentd, VDAGENTD_FILE_XFER_STATUS, msg->id, VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA, NULL, 0); + g_free(file_path); g_free(path); + g_free(dir); return ; error: @@ -219,7 +226,9 @@ error: msg->id, VD_AGENT_FILE_XFER_STATUS_ERROR, NULL, 0); if (task) vdagent_file_xfer_task_free(task); + g_free(file_path); g_free(path); + g_free(dir); } void vdagent_file_xfers_status(struct vdagent_file_xfers *xfers, |