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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileserver: Browse symlink display shows the target #5973

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

armadi1809
Copy link
Contributor

Resolves #5810

I tested this change with both the file_server directive as well as the caddy file-server command and it's working for both. Please let me know if I missed something.

@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch from bbd4558 to 11b4986 Compare December 12, 2023 03:35
@armadi1809
Copy link
Contributor Author

Just ran gofumpt -w on the changed file. The linting issue should be resolved.

@mholt
Copy link
Member

mholt commented Dec 18, 2023

Thanks for the PR! My only thought is that maybe dereferencing a symlink should be optional. Some people may not want to show the linked path information. How would you feel about implementing a simple config setting for this?

@mholt mholt added the under review 🧐 Review is pending before merging label Dec 18, 2023
@francislavoie francislavoie changed the title Changed symlink display name to use the symlink representation in browser fileserver: Changed browse symlink display to show target Dec 18, 2023
@francislavoie francislavoie changed the title fileserver: Changed browse symlink display to show target fileserver: Browse symlink display shows the target Dec 18, 2023
@armadi1809
Copy link
Contributor Author

@mholt sure thing! One question to make sure I understand this correctly. The config setting will be part of the browse sub-directive syntax? If not, Is there another place in the codebase where we are doing something similar that I can take inspiration from? Thank you for taking the time to review this!

@mholt
Copy link
Member

mholt commented Dec 18, 2023

Yeah, it'd likely have to be a subdirective of the browse subdirective. 😅 Maybe something like reveal_symlinks? Or if it's for hard links too, maybe reveal_links?

@armadi1809
Copy link
Contributor Author

Sounds good. Thanks for the clarification.

@steffenbusch
Copy link
Contributor

Thank you for making this an opt-in. I use the browse template to show certain users/clients what files they can download and some of them are sym-linked to a central location and I would not like to reveal this internal thing.

@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch 3 times, most recently from e91dbeb to a815cff Compare December 21, 2023 00:57
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I'm looking forward to merging this, I just had a few last-minute thoughts before we do.


symLinkTarget, err := filepath.EvalSymlinks(path)
if err == nil {
symLinkRepresentation = name + " -> " + symLinkTarget
Copy link
Member

Choose a reason for hiding this comment

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

Actually, how about if we use a Tabler SVG icon for this arrow?

<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrow-narrow-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l14 0" /><path d="M15 16l4 -4" /><path d="M15 8l4 4" /></svg>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, do we just add the svg tag mentioned above to the symLinkRepresentation string or is there another/better way of doing it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, just replace the " -> " string with the " <svg ...> " string.

You could move that into a separate variable for readability though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just trying this and the " <svg ...> " gets displayed as it is inside the html. I believe the value passed to the go template needs to be of type template.HTML in order for it to parse it as html rather than the raw string. If so, how do you suggest we treat this?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that's probably true. In that case, the correct way to handle this would be to create a new field in the fileInfo struct, maybe called Symlink or SymlinkName or SymlinkPath or something. Then the UI will render the arrow SVG icon and the symlink info. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mholt I think I got what you mean. As you can see now, I added a field called SymlinkPath to the fileInfo struct. This new field is a slice of strings that can either be empty or containing two elements (first one being the name of the symlink and the second one being the target of the symlink). This slice gets filled in only when the file is a symlink and the reveal_symlinks directive is enabled. Therefore, in the browse.html file we can check if this slice is empty and in that case display the name otherwise display the first element of the slice followed by theS SVG icon followed by the second element of the slice. Is this a valid approach?

modules/caddyhttp/fileserver/caddyfile.go Outdated Show resolved Hide resolved
modules/caddyhttp/fileserver/command.go Outdated Show resolved Hide resolved
modules/caddyhttp/fileserver/browsetplcontext.go Outdated Show resolved Hide resolved
modules/caddyhttp/fileserver/browse.go Outdated Show resolved Hide resolved
@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch 2 times, most recently from be8648d to d04bdd9 Compare January 9, 2024 04:33
@armadi1809
Copy link
Contributor Author

@mholt All the feedback items should be addressed now. The only one not resolved yet is the "" vs "->" and as mentioned in the comment above, I was getting the raw "..." string when inserting it directly into the symlink representation as recommended. Thanks again for your continuous help with this!

@mholt
Copy link
Member

mholt commented Jan 9, 2024

Thanks! Just had a sit at my desk and was able to comprehend what you meant, I just replied above.

@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch from d04bdd9 to 6604ba3 Compare January 10, 2024 01:09
@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch from 6604ba3 to 3ecc69f Compare January 22, 2024 03:45
@armadi1809
Copy link
Contributor Author

@mholt I resolved a conflict inside ./modules/caddyhttp/fileserver/caddyfile.go that emerged after the recent modifications to that file in #5850. This should be ready to be merged again if you still want this feature. Thank you!

@armadi1809 armadi1809 force-pushed the list-symlinks-as-symlinks branch from 3ecc69f to ae9b605 Compare January 23, 2024 18:13
@mholt mholt enabled auto-merge (squash) January 24, 2024 00:08
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

This LGTM now. Thanks so much for iterating on this with us, @armadi1809 -- hopefully people will find it useful!

@francislavoie francislavoie added this to the v2.8.0 milestone Jan 24, 2024
@francislavoie francislavoie added feature ⚙️ New feature or request and removed under review 🧐 Review is pending before merging labels Jan 24, 2024
@mholt mholt merged commit feb07a7 into caddyserver:master Feb 6, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: file-server browser, allow for listing symlinks as symlinks
4 participants