Can't restore files from the trash can if it contains spaces...

Axel FILMORE axel.filmore at gmail.com
Thu Jun 21 13:16:18 UTC 2012


Hey hackers,

I found this problem with LibFm, tested with last sources from git master.

Create a file called "New1".
Create a file called "New 1".
Create a file with special characters, like accentuated ones,
for example : "Accentué"

Trash these files, then from the Trash Can click restore.

On my system I can only restore "New1", I get an error with other files.
(Tested with src/libfm-demo)

I fixed it this way :

GFile *fm_path_to_gfile (FmPath *path)
{
     GFile *gf;

     char *str = fm_path_to_str (path);

     if (fm_path_is_native (path))
     {
         gf = g_file_new_for_path (str);
     }
     else
     {
         // Escape the path so that it supports spaces and special 
characters like accentuated ones...
         char *tmp_str = g_uri_escape_string (str, 
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);

         gf = g_file_new_for_uri (tmp_str);
         g_free (tmp_str);
     }

     g_free (str);

     return gf;
}



g_uri_escape_string adds escape characters,

"trash:///\home\hotnuma\Bureau\.Trash-1000\files\New%201"

becomes :

"trash:///%5Chome%5Chotnuma%5CBureau%5C.Trash-1000%5Cfiles%5CNew%25201"

That's what you get if you copy the file from Nautilus or Thunar and 
paste the string in a text editor.


I found also a problem in fm_str_replace

I fixed it this way :


char *fm_str_replace (char *str, char *old, char *new)
{
     int i;
     int len = strlen (str);
     int old_len = strlen (old);

     GString *buf = g_string_sized_new (len);

     char *found;
     while (found = strstr (str, old))
     {
         g_string_append_len (buf, str,  (found - str));
         g_string_append (buf, new);
         str = found + old_len;
     }
     for (; *str; ++str)
         g_string_append_c (buf, *str);
     return g_string_free (buf, FALSE);
}



"str = found + old_len;" instead of "str = found + 1;"


Cheers!


-- 
Axel FILMORE
#--------------------------------------------#
         https://github.com/afilmore
#--------------------------------------------#
  Vala - Compiler For The GObject Type System
         https://live.gnome.org/Vala
#--------------------------------------------#



More information about the Lubuntu-users mailing list