Ticket #873: filename_escape.patch
| File filename_escape.patch, 3.2 KB (added by savago, 4 years ago) |
|---|
-
src/filename_scape.h
1 #ifndef __FILENAME_SCAPER__ 2 #define __FILENAME_SCAPER__ 3 4 /** 5 * @file filename_scape.h 6 * @author Adenilson Cavalcanti <savagobr@yahoo.com> 7 * @date Tue Oct 21 15:31:10 2008 8 * 9 * @brief An auxiliary module to scape invalid characters from filename. 10 * 11 * This code is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this library; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 25 */ 26 27 static const char reserved_chars[] = { '/', '!', '?', ':', '*', '\\', '>', '<', '@' }; 28 static const int reserved_count = 9; 29 static const char scaper = '_'; 30 31 static void filename_scape_characters(char *input) 32 { 33 34 int i; 35 36 while (*input) { 37 for (i = 0; i < reserved_count; ++i) 38 if (*input == reserved_chars[i]) { 39 *input++ = scaper; 40 goto done; 41 } 42 ++input; 43 done: 44 ; 45 } 46 47 } 48 49 #endif -
src/file_sync.c
19 19 */ 20 20 21 21 #include "file_sync.h" 22 #include "filename_scape.h" 22 23 #include <opensync/file.h> 23 24 #include <opensync/opensync-version.h> 24 25 #include <assert.h> … … 143 144 char *buffer = NULL; 144 145 unsigned int size = 0; 145 146 146 char *filename = g_strdup_printf ("%s/%s", dir->path, osync_change_get_uid(change)); 147 147 char *filename = NULL, *tmp = NULL; 148 if (!(tmp = strdup(osync_change_get_uid(change)))) { 149 osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 150 return; 151 } 152 filename_scape_characters(tmp); 153 154 filename = g_strdup_printf ("%s/%s", dir->path, tmp); 155 free(tmp); 156 148 157 switch (osync_change_get_changetype(change)) { 149 158 case OSYNC_CHANGE_TYPE_DELETED: 150 159 if (!remove(filename) == 0) { … … 412 421 OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 413 422 OSyncFileDir *dir = osync_objtype_sink_get_userdata(sink); 414 423 415 char *filename = NULL ;424 char *filename = NULL, *tmp; 416 425 417 426 if (!osync_filesync_write(data, info, ctx, change)) { 418 427 osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 419 428 return; 420 429 } 421 422 filename = g_strdup_printf ("%s/%s", dir->path, osync_change_get_uid(change)); 430 if (!(tmp = strdup(osync_change_get_uid(change)))) { 431 osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 432 return; 433 } 434 filename_scape_characters(tmp); 435 436 filename = g_strdup_printf ("%s/%s", dir->path, tmp); 437 free(tmp); 423 438 char *hash = NULL; 424 439 425 440 if (osync_change_get_changetype(change) != OSYNC_CHANGE_TYPE_DELETED) {
