Skip to content

Conversation

@gerardbosch
Copy link

Proposed changes

Fix/add support for JAR/WAR files with shell associations.

The file command apparently behaves inconsistently between Linux distributions—that prevents opening JAR files (which are just ZIP files with metadata) in Manjaro/Arch Linux within Midnight Commander; and inspecting/editing source code within those compressed files.

WAR files were missing (that was reported here): https://bugs.launchpad.net/mc/+bug/2062968/comments/16 - this PR adds support for them via extension match.

Checklist

👉 Our coding style can be found here: https://midnight-commander.org/coding-style/ 👈

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions bot added this to the Future Releases milestone Nov 6, 2025
@github-actions github-actions bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Nov 6, 2025
Copy link
Contributor

@ossilator ossilator left a comment

Choose a reason for hiding this comment

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

i find the whole approach mildly fishy; see the inline comment.


the lines in the commit message are a bit long.


[jar-by-shell]
Shell=.jar
TypeIgnoreCase=true
Copy link
Contributor

Choose a reason for hiding this comment

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

that's the wrong keyword here.

Copy link
Member

Choose a reason for hiding this comment

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

Yep 👍

View=%view{ascii} @EXTHELPERSDIR@/archive.sh view zip

[war-by-shell]
Shell=.war
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than duplicating the whole thing, a regex match would be preferred.

Copy link
Member

Choose a reason for hiding this comment

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

As the submitter predictably disappeared, as it usually turns out to be the case, I have updated the code myself.


[jar]
[jar-by-type]
Type=\\(Java (Jar file|archive) data \\((zip|JAR)\\)\\)
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the addition of .war handling below, it would seem logical to add it here as well, or does no file variant recognize these as anything other than a regular zip archive?

actually, what are the files recognized as? you're not saying in the commit message.

the idea behind using content based detection is to catch files with non-standard extensions (for .jars, that may be modules in some applications). falling back to extension based detection is basically admitting defeat ...

Copy link
Member

Choose a reason for hiding this comment

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

As far as I understand, wars are nothing other than jars, only meant to be uploaded to the application servers, so file output would be the same for both. In this sense, they have always been implicitly supported, or at least they should have been.

Given a number of recent posts to #4862 tickets, however, I think indeed it's time to admit defeat and add extension-based fallbacks. It seems that the problem is that even though we are now correctly matching on the file output, the utility itself is unreliable and often enough doesn't detect the correct type.

Copy link
Contributor

Choose a reason for hiding this comment

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

.wars contain additional metadata, so they could be detected separately.

i'd really like to see the exact status quo documented (in the commit message), so it's obvious what is being worked around and that this is the only reasonable way to do it.

@azazar
Copy link

azazar commented Jan 19, 2026

Why not identify files by content when extension associations search fails? Like Far Manager does.

@zyv
Copy link
Member

zyv commented Jan 20, 2026

Why not identify files by content when extension associations search fails? Like Far Manager does.

This PR does exactly the opposite: identify by extension if content search fails (which apparently happens for a surprisingly high number of users even after all the fixes that we've made to it).

@zyv zyv changed the title fix(misc/file-handler): Handling to open JAR and WAR files Add extension-based fallbacks for handling JAR and WAR files to mc.ext Jan 31, 2026
@zyv zyv added area: vfs Virtual File System support and removed needs triage Needs triage by maintainers labels Jan 31, 2026
…ling JAR and WAR files to mc.ext

The `file` command apparently behaves inconsistently between Linux
distributions—that prevents opening JAR files (which are just ZIP files with
metadata) in Manjaro/Arch Linux within Midnight Commander; and
inspecting/editing source code within those compressed files.

Signed-off-by: Gerard Bosch <30733556+gerardbosch@users.noreply.github.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
@zyv zyv force-pushed the fix/jar-handler branch from 083f690 to 76c56d7 Compare January 31, 2026 16:41
@zyv zyv modified the milestones: Future Releases, 4.9.0 Jan 31, 2026
@zyv zyv requested review from mc-worker and ossilator January 31, 2026 16:45
@zyv zyv changed the title Add extension-based fallbacks for handling JAR and WAR files to mc.ext Ticket #4861: add extension-based fallbacks for handling JAR and WAR files to mc.ext Jan 31, 2026
View=%view{ascii} @EXTHELPERSDIR@/archive.sh view zip

[jar-war-by-regex]
Regex=\\.(j|w)ar$
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use [jw] instead of (j|w). i have no preference.


[jar]
[jar-by-type]
Type=\\(Java (Jar file|archive) data \\((zip|JAR)\\)\\)
Copy link
Contributor

Choose a reason for hiding this comment

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

.wars contain additional metadata, so they could be detected separately.

i'd really like to see the exact status quo documented (in the commit message), so it's obvious what is being worked around and that this is the only reasonable way to do it.

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

Labels

area: vfs Virtual File System support prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

Cannot open .jar files: file output doesn't match & missing [jar-by-shell]

4 participants