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
Realm IDs are now its absolute path instead of its hashcode #1054
Conversation
@@ -158,7 +157,7 @@ | |||
private Handler handler; | |||
|
|||
private final byte[] key; | |||
private final int id; | |||
private final String id; |
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 this can be renamed to absolutePath
We already have a path variabel we can use instead. I was just weary to overload the meaning of the name. But removing it completely and just use path is fine with me. It also removes the ambiguity we have in some of the static methods that manually calculate the ID atm. |
if we use path as ID, it's better to use canonical path instead of absolute path. |
👍 for @zaki50 proposal |
ID's are only local and used on runtime. If we cached them on disk, I would probably agree, but right now I don't think we need the extra security or is there something I am missing? |
The problem is the opposite. Two absolute paths can point to the same file. |
True, but wouldn't you really have to go out of the way to make that happen, eg.
I am not against it per se, but at least on Android I doubt this will be an issue, so introducing a slowdown for a really small corner case? Especially considering that even if you did do this, you would "just" have two instances of a Realm which would hog resources, but it wouldn't cause errors. |
Maybe we can check if the string contains |
Throwing seems kinda harsh though. We could also add a check for ".." and then fallback to canonical path if needed.
This introduces a slowdown of about 10x for paths not containing "..". Neither of these solutions work with symlinks though, but we shouldn't encounter them on Android at least (we probably will on the server side) |
You last solution looks fine. We can document the performance drop in the Javadoc. Only Java8 has proper support for symlinks so there's that |
there are some other corner cases.
"./" or simply "/" is better for fallback condition, I think. |
Good point. Thinking about this a bit more, then ti would probably be cleaner just to use canonicalPath() and then take the performance hit. Once we introduce RealmConfiguration #929 , this becomes less of an issue anyway since we are only going to calculate it once. |
Note, I deprecated |
I think getPath() is enough because we have just single getter of path. |
Bump @emanuelez |
👍 |
1 similar comment
👍 |
Realm IDs are now its canonical path instead of its hashcode
Fixes #1040
@emanuelez @bmunkholm @kneth