inotify: Avoid empty root directory string

When gio monitors a directory, it will delete the extra "/" at the end
of the directory string, but when the directory is "/", this will cause
the modified directory string to be empty, and eventually the
monitoring will fail. The solution is to delete only if the directory
string length is greater than 1.
This commit is contained in:
wangrong 2023-01-29 02:33:54 +00:00
parent 548d917f35
commit 2643961845

View File

@ -36,7 +36,7 @@ dup_dirname (const gchar *dirname)
gchar *d_dirname = g_strdup (dirname);
size_t len = strlen (d_dirname);
if (d_dirname[len - 1] == '/')
if (len > 1 && d_dirname[len - 1] == '/')
d_dirname[len - 1] = '\0';
return d_dirname;