Skip to content

Commit 9991fb1

Browse files
Max-Elukefromdc
authored andcommitted
[libcaja-private] Re-check file MIME type before picking an application.
An example of when the MIME type might change: a file is initially created with 0 bytes of content, but more data is added later. Empty files are always detected as plain text, but the file might not be empty anymore when the user opens it. This commit affects the behavior when double-clicking a file and when right- clicking on it too.
1 parent e51b16d commit 9991fb1

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

libcaja-private/caja-file.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,24 @@ caja_file_update_info (CajaFile *file,
25552555
return update_info_internal (file, info, FALSE);
25562556
}
25572557

2558+
void
2559+
caja_file_refresh_info (CajaFile *file)
2560+
{
2561+
GFile *gfile;
2562+
GFileInfo *new_info;
2563+
2564+
gfile = caja_file_get_location (file);
2565+
new_info = g_file_query_info (gfile, CAJA_FILE_DEFAULT_ATTRIBUTES,
2566+
G_FILE_QUERY_INFO_NONE, NULL, NULL);
2567+
if (new_info != NULL) {
2568+
if (caja_file_update_info (file, new_info)) {
2569+
caja_file_changed (file);
2570+
}
2571+
g_object_unref (new_info);
2572+
}
2573+
g_object_unref (gfile);
2574+
}
2575+
25582576
static gboolean
25592577
update_name_internal (CajaFile *file,
25602578
const char *name,

libcaja-private/caja-file.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ void caja_file_monitor_add (CajaFile
144144
void caja_file_monitor_remove (CajaFile *file,
145145
gconstpointer client);
146146

147+
/* Synchronously refreshes file info from disk.
148+
* This can call caja_file_changed, so don't call this function from any
149+
* of the callbacks for that event.
150+
*/
151+
void caja_file_refresh_info (CajaFile *file);
152+
147153
/* Waiting for data that's read asynchronously.
148154
* This interface currently works only for metadata, but could be expanded
149155
* to other attributes as well.

libcaja-private/caja-mime-actions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,12 @@ make_activation_parameters (GList *uris,
997997
uri = l->data;
998998
file = caja_file_get_by_uri (uri);
999999

1000+
/* Double-check if a file's MIME type has changed before we commit to a
1001+
choice of application for it. This can happen if, for instance, file
1002+
was originally created with 0 bytes and then content was added to it
1003+
later-- it will change from plaintext to something else. */
1004+
caja_file_refresh_info (file);
1005+
10001006
app = caja_mime_get_default_application_for_file (file);
10011007
if (app != NULL)
10021008
{

src/file-manager/fm-directory-view.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8813,6 +8813,13 @@ real_update_menus (FMDirectoryView *view)
88138813

88148814
file = CAJA_FILE (l->data);
88158815

8816+
/* Double-check if the files' MIME types have changed before we
8817+
commit to a choice of applications for them. This can happen
8818+
if, for instance, a file was originally created with 0 bytes
8819+
and then content was added to it later-- it will change from
8820+
plaintext to something else. */
8821+
caja_file_refresh_info (file);
8822+
88168823
if (!caja_mime_file_opens_in_external_app (file)) {
88178824
show_app = FALSE;
88188825
}

0 commit comments

Comments
 (0)