Skip to content

Commit 2149626

Browse files
robertxgrayraveit65
authored and
raveit65
committedApr 2, 2021
Improved filesystem check on dnd
1 parent 66a7219 commit 2149626

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed
 

‎libcaja-private/caja-dnd.c

+28-14
Original file line numberDiff line numberDiff line change
@@ -374,29 +374,43 @@ caja_drag_default_drop_action_for_netscape_url (GdkDragContext *context)
374374
}
375375

376376
static gboolean
377-
check_same_fs (CajaFile *file1,
378-
CajaFile *file2)
377+
check_same_fs (const char *target_uri,
378+
CajaFile *target_file,
379+
const char *dropped_uri,
380+
CajaFile *dropped_file)
379381
{
380382
gboolean result;
381383

382384
result = FALSE;
383385

384-
if (file1 != NULL && file2 != NULL)
385-
{
386-
char *id1, *id2;
386+
char *target_fs = NULL, *dropped_fs = NULL;
387387

388-
id1 = caja_file_get_filesystem_id (file1);
389-
id2 = caja_file_get_filesystem_id (file2);
388+
if (target_file != NULL)
389+
{
390+
target_fs = caja_file_get_filesystem_id (target_file);
391+
}
392+
if (target_fs == NULL)
393+
{
394+
target_fs = caja_get_filesystem_id_by_uri (target_uri, TRUE);
395+
}
390396

391-
if (id1 != NULL && id2 != NULL)
392-
{
393-
result = (strcmp (id1, id2) == 0);
394-
}
397+
if (dropped_file != NULL && !caja_file_is_symbolic_link (dropped_file))
398+
{
399+
dropped_fs = caja_file_get_filesystem_id (dropped_file);
400+
}
401+
if (dropped_fs == NULL)
402+
{
403+
dropped_fs = caja_get_filesystem_id_by_uri (dropped_uri, FALSE);
404+
}
395405

396-
g_free (id1);
397-
g_free (id2);
406+
if (target_fs != NULL && dropped_fs != NULL)
407+
{
408+
result = (strcmp (target_fs, dropped_fs) == 0);
398409
}
399410

411+
g_free (target_fs);
412+
g_free (dropped_fs);
413+
400414
return result;
401415
}
402416

@@ -519,7 +533,7 @@ caja_drag_default_drop_action_for_icons (GdkDragContext *context,
519533
target = g_file_new_for_uri (target_uri_string);
520534
}
521535

522-
same_fs = check_same_fs (target_file, dropped_file);
536+
same_fs = check_same_fs (target_uri_string, target_file, dropped_uri, dropped_file);
523537

524538
caja_file_unref (dropped_file);
525539
caja_file_unref (target_file);

‎libcaja-private/caja-file-utilities.c

+36
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,42 @@ caja_restore_files_from_trash (GList *files,
12991299
caja_file_list_unref (unhandled_files);
13001300
}
13011301

1302+
char *
1303+
caja_get_filesystem_id_by_location (GFile *location, gboolean follow)
1304+
{
1305+
GFileInfo *info;
1306+
GFileQueryInfoFlags flags;
1307+
char *filesystem_id = NULL;
1308+
1309+
if (follow) {
1310+
flags = G_FILE_QUERY_INFO_NONE;
1311+
} else {
1312+
flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
1313+
}
1314+
1315+
info = g_file_query_info (location, G_FILE_ATTRIBUTE_ID_FILESYSTEM, flags, NULL, NULL);
1316+
if (info) {
1317+
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM)) {
1318+
filesystem_id = g_strdup (
1319+
g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM));
1320+
}
1321+
g_object_unref (info);
1322+
}
1323+
return filesystem_id;
1324+
}
1325+
1326+
char *
1327+
caja_get_filesystem_id_by_uri (const char *uri, gboolean follow)
1328+
{
1329+
GFile *location;
1330+
char *filesystem_id;
1331+
1332+
location = g_file_new_for_uri (uri);
1333+
filesystem_id = caja_get_filesystem_id_by_location (location, follow);
1334+
g_object_unref (location);
1335+
return filesystem_id;
1336+
}
1337+
13021338
#if !defined (CAJA_OMIT_SELF_CHECK)
13031339

13041340
void

‎libcaja-private/caja-file-utilities.h

+2
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,7 @@ GHashTable * caja_trashed_files_get_original_directories (GList *files,
9494
GList **unhandled_files);
9595
void caja_restore_files_from_trash (GList *files,
9696
GtkWindow *parent_window);
97+
char * caja_get_filesystem_id_by_location (GFile *location, gboolean follow);
98+
char * caja_get_filesystem_id_by_uri (const char *uri, gboolean follow);
9799

98100
#endif /* CAJA_FILE_UTILITIES_H */

0 commit comments

Comments
 (0)
Please sign in to comment.