-
Notifications
You must be signed in to change notification settings - Fork 155
redirect from invalid file url #4633
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
base: master
Are you sure you want to change the base?
Conversation
This looks good and does fix the double error message, but I wonder if we should bump them to the first valid directory instead of straight home? Maybe some brainstorming around how you get into this situation would help, but say I have a file Not sure if this scenario is realistic, it would require iteratively validating the path, but depending on how we do this it might be ok performance wise. Also happy to hear if there are any use cases that you had in mind for this error. |
I think that's a good idea! Originally, I was concerned about if I were to type in Still, I think it makes sense to attempt to go back at least one directory, and either fallback to home when none can be found or just redirect to home if the immediate previous directory is valid. If we validate directories because actually redirecting, I don't think performance will be an issue, I'm just not sure which is better for the user. |
Yeah the question is whether we have a good way of checking a path exists without redirecting. Since we always pass the absolute path in the url, it could be as simple as path = false
while !path
begin
File.new(url_path) # Errors if path doesn't exist
path = url_path
rescue
url_path = url_path.split('/')[0...-1].join('/')
end
end but using some features from the PathName class that I don't know off the top of my head |
I just realized the original issue is somewhat of a self-inflicted issue. I agree that defaulting to the closest existing directory would make the most sense, with a single redirect and some potential extra checks at the end (e.g. in our case,
I believe the easiest way would be something like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
render :index | ||
next_valid = @path.path.ascend.find(&:readable?) | ||
redirected_location = next_valid.nil? ? Dir.home : next_valid | ||
redirect_to(files_path(redirected_location), alert: exception.message.to_s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For remote directories, this redirects back to the root - /
- of the local file system.
If you enter the URL there is no referrer, so that's unfortunate. Seems like we need some sort of toggle for remote and local paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not attempt to reach each possible remote path before redirecting to the local filesystem? My understanding was that next_valid
is only nil if there were no directories readable by traversing the entire path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have to look at the implementation of remote_file.rb
to figure it out. I'm not sure what @path.path
actually is out of remote_file and if ascend
on that object actually traverses the remote file system at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so @path
is an actual Pathname
but since it's a remote file system it won't actually traverse the remote, instead traversing the local filesystem and the root /
is the only common location on both.
@path = Pathname.new(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess by toggle I meant more like if it's a local path, redirect back to the top most readable directory, but if it's a remote directory ... I guess just redirect back to home as we can't know where else to go.
end | ||
|
||
def readable? | ||
RcloneUtil.readable?(remote, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #4360
This error only occurred when attempting to access a nonexistent directory directly from the URL, not when using the "Change Directory" button. It also brought the user to a table that appeared to have navigated to the nonexistent directory, with the buttons to create files and directories still present but causing errors when clicked.
Instead, the user is redirected to the home directory when trying to access a nonexistent directory by URL.