Skip to content

Sniff remote files mimetype#3802

Open
leigh123linux wants to merge 1 commit into
linuxmint:masterfrom
leigh123linux:sniff_remote_file_type
Open

Sniff remote files mimetype#3802
leigh123linux wants to merge 1 commit into
linuxmint:masterfrom
leigh123linux:sniff_remote_file_type

Conversation

@leigh123linux

@leigh123linux leigh123linux commented Jul 5, 2026

Copy link
Copy Markdown
Member

This PR addresses the issue by adding a remote-file MIME sniffing fallback so that files reported as application/octet-stream over SFTP/SSH/FTP are re-evaluated from their contents (so ASCII/text files can open in a text editor instead of being treated as binary/archives).

Changes:

Introduces an async read-and-sniff path for remote (non-native) files that initially resolve to application/octet-stream.
Adds a per-file guard flag (mime_type_sniffed) to avoid repeated sniffing / prevent later overwrites back to octet-stream.
Resets the sniff guard when clearing file info.

Fixes. #2319

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #2319 by adding a remote-file MIME sniffing fallback so that files reported as application/octet-stream over SFTP/SSH are re-evaluated from their contents (so ASCII/text files can open in a text editor instead of being treated as binary/archives).

Changes:

  • Introduces an async read-and-sniff path for remote (non-native) files that initially resolve to application/octet-stream.
  • Adds a per-file guard flag (mime_type_sniffed) to avoid repeated sniffing / prevent later overwrites back to octet-stream.
  • Resets the sniff guard when clearing file info.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
libnemo-private/nemo-file.c Adds async remote MIME sniffing and integrates it into update_info_internal() when MIME resolves to octet-stream.
libnemo-private/nemo-file-private.h Adds a new mime_type_sniffed bitfield to track sniffing state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2314 to +2319
g_input_stream_close_async (G_INPUT_STREAM (source), G_PRIORITY_LOW, NULL, NULL, NULL);
mime_sniff_data_free (data);
}

static void
mime_sniff_open_cb (GObject *source, GAsyncResult *res, gpointer user_data)
Comment on lines +2820 to +2833
if (!file->details->mime_type_sniffed &&
g_strcmp0 (file->details->mime_type, "application/octet-stream") == 0) {
GFile *location = nemo_file_get_location (file);

file->details->mime_type_sniffed = TRUE;

if (location != NULL) {
if (!g_file_is_native (location) &&
size > 0 && size <= NEMO_MIME_SNIFF_MAX_SIZE) {
nemo_file_sniff_remote_mime_type_async (file, location);
}
g_object_unref (location);
}
}
Comment on lines 85 to +88
GRefString *mime_type;


eel_boolean_bit mime_type_sniffed : 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants