diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2012-07-21 13:48:35 +0000 |
---|---|---|
committer | Vincent Torri <vincent.torri@gmail.com> | 2012-07-21 13:48:35 +0000 |
commit | 7e40b5f15a1f8bf9ce35436dbb0dc4191423e6b0 (patch) | |
tree | 8d03145fa64b8a353cf842f17f48befa86f6e751 | |
parent | 58be84aa8e0a5817e6b259049d4a27e094a7cab4 (diff) |
E17: symlink fixes
when copying symlinks, it creates a symlink to the
destination but with the name of the pointed file/folder.
It causes problems, ex: we can't copy two symlinks
pointing to the same file, because they will have the
same name.
Also when copying, if it's a link, we fill the destination
in the struct task, then, after we check overwrite with
_e_fm_op_handle_overwrite()
Here is a patch which corrects this.
Patch by Maxime Villard (rustyBSD), modified a bit by me (add 2 free() + formatting)
SVN revision: 74264
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/bin/e_fm_op.c | 38 |
2 files changed, 30 insertions, 9 deletions
@@ -34,3 +34,4 @@ Gwanglim Lee <gl77.lee@samsung.com> | |||
34 | Thomas Gstädtner <thomas@gstaedtner.net> | 34 | Thomas Gstädtner <thomas@gstaedtner.net> |
35 | q66 <quaker66@gmail.com> | 35 | q66 <quaker66@gmail.com> |
36 | Tom Hacohen (TAsn) <tom@stosb.com> | 36 | Tom Hacohen (TAsn) <tom@stosb.com> |
37 | Maxime Villard <rustyBSD@gmx.fr> | ||
diff --git a/src/bin/e_fm_op.c b/src/bin/e_fm_op.c index e593a9a8c..dfec0fea8 100644 --- a/src/bin/e_fm_op.c +++ b/src/bin/e_fm_op.c | |||
@@ -1163,30 +1163,30 @@ _e_fm_op_copy_dir(E_Fm_Op_Task *task) | |||
1163 | static int | 1163 | static int |
1164 | _e_fm_op_copy_link(E_Fm_Op_Task *task) | 1164 | _e_fm_op_copy_link(E_Fm_Op_Task *task) |
1165 | { | 1165 | { |
1166 | int len; | 1166 | char *lnk_path; |
1167 | char path[PATH_MAX]; | ||
1168 | 1167 | ||
1169 | len = readlink(task->src.name, path, sizeof(path) - 1); | 1168 | lnk_path = ecore_file_readlink(task->src.name); |
1170 | if (len < 0) | 1169 | if (!lnk_path) |
1171 | { | 1170 | { |
1172 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot read link '%s'.", task->src.name); | 1171 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot read link '%s'.", task->src.name); |
1173 | } | 1172 | } |
1174 | else | 1173 | else |
1175 | { | 1174 | { |
1176 | path[len] = 0; | 1175 | E_FM_OP_DEBUG("Creating link from '%s' to '%s'\n", lnk_path, task->dst.name); |
1177 | 1176 | ||
1178 | if (symlink(path, task->dst.name) != 0) | 1177 | if (symlink(lnk_path, task->dst.name) != 0) |
1179 | { | 1178 | { |
1180 | if (errno == EEXIST) | 1179 | if (errno == EEXIST) |
1181 | { | 1180 | { |
1182 | if (unlink(task->dst.name) == -1) | 1181 | if (unlink(task->dst.name) == -1) |
1183 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot unlink '%s': %s.", task->dst.name); | 1182 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot unlink '%s': %s.", task->dst.name); |
1184 | if (symlink(path, task->dst.name) == -1) | 1183 | if (symlink(lnk_path, task->dst.name) == -1) |
1185 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", path, task->dst.name); | 1184 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", lnk_path, task->dst.name); |
1186 | } | 1185 | } |
1187 | else | 1186 | else |
1188 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", path, task->dst.name); | 1187 | _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot create link from '%s' to '%s': %s.", lnk_path, task->dst.name); |
1189 | } | 1188 | } |
1189 | free(lnk_path); | ||
1190 | } | 1190 | } |
1191 | task->dst.done += task->src.st.st_size; | 1191 | task->dst.done += task->src.st.st_size; |
1192 | 1192 | ||
@@ -1347,6 +1347,26 @@ _e_fm_op_copy_atom(E_Fm_Op_Task *task) | |||
1347 | return 1; | 1347 | return 1; |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | if (S_ISLNK(task->src.st.st_mode)) | ||
1351 | { | ||
1352 | char *dst_dir; | ||
1353 | |||
1354 | dst_dir = ecore_file_dir_get(task->dst.name); | ||
1355 | if (dst_dir) | ||
1356 | { | ||
1357 | char dst_path[PATH_MAX]; | ||
1358 | const char *dst_name; | ||
1359 | |||
1360 | dst_name = ecore_file_file_get(task->src.name); | ||
1361 | if ((strlen(dst_dir) + strlen(dst_name)) >= PATH_MAX) | ||
1362 | _E_FM_OP_ERROR_SEND_WORK(task, 0, "Not copying link: path too long", dst_path); | ||
1363 | |||
1364 | snprintf(dst_path, sizeof(dst_path), "%s/%s", dst_dir, dst_name); | ||
1365 | task->dst.name = strdup(dst_path); | ||
1366 | free(dst_dir); | ||
1367 | } | ||
1368 | } | ||
1369 | |||
1350 | if (_e_fm_op_handle_overwrite(task)) return 1; | 1370 | if (_e_fm_op_handle_overwrite(task)) return 1; |
1351 | 1371 | ||
1352 | if (S_ISDIR(task->src.st.st_mode)) | 1372 | if (S_ISDIR(task->src.st.st_mode)) |