Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow disabling file detections by reading header #1175

Merged
merged 6 commits into from
Jan 7, 2021

Conversation

WeidiDeng
Copy link
Contributor

Description
This pr solves the issue and provides a frontend to set the options.

馃毃 Before submitting your PR, please read community, and indicate which issues (in any of the repos) are either fixed or closed by this PR. See GitHub Help: Closing issues using keywords.

  • DO make sure you are requesting to pull a topic/feature/bugfix branch (right side). Don't request your master!
  • DO make sure you are making a pull request against the master branch (left side). Also you should start your branch off our master.
  • DO make sure that File Browser can be successfully built. See builds and development.
  • DO make sure that related issues are opened in other repositories. I.e., the frontend, caddy plugins or the web page need to be updated accordingly.
  • AVOID breaking the continuous integration build.

Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did, what alternatives you considered, etc.

鉂わ笍 Thank you!

@o1egl
Copy link
Member

o1egl commented Dec 4, 2020

This is actually a duplicate of #1168

@WeidiDeng
Copy link
Contributor Author

but that pr doesn't have the updated vue ui, no option exposed yet

@o1egl
Copy link
Member

o1egl commented Dec 12, 2020

I don't think that we need any ui for that. Configuring this option per user doesn't make sense.

@WeidiDeng
Copy link
Contributor Author

Perhaps this can be made in a global option, the one that uses commandline to set options. An array of relatives path to root, that skips type detection.

I tried the other pr. Mostly it works fine, however I have a directory full of subtitle files (sass extension), the mime type detection fails, directory become very slow to show.

Copy link
Member

@o1egl o1egl left a comment

Choose a reason for hiding this comment

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

In my opinion it doesn't make sense to disable it for specific paths only. It should be a global single boolean param.

files/file.go Outdated
Comment on lines 265 to 271
if detectDisabled {
file.Type = "blob"
} else {
err := file.detectType(true, false)
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

We should only disable file detection by header. Simple ext based detection shouldn't be disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I incorporate the changes from pr.

@WeidiDeng WeidiDeng changed the title allow disabling file detections for paths allow disabling file detections by reading header Dec 29, 2020
rules/rules.go Outdated
@@ -9,6 +9,7 @@ import (
// Checker is a Rules checker.
type Checker interface {
Check(path string) bool
ReadHeader() bool
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that it is the right place to add this method

files/file.go Outdated
@@ -261,7 +269,7 @@ func (i *FileInfo) readListing(checker rules.Checker) error {
} else {
listing.NumFiles++

err := file.detectType(true, false)
err := file.detectType(true, false, checker.ReadHeader())
Copy link
Member

Choose a reason for hiding this comment

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

Better would be to add a boolean param to the readListing func

@o1egl
Copy link
Member

o1egl commented Dec 29, 2020

Instead of extending Checker interface you can add a boolean param to the FileOptions struct.

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.

None yet

2 participants