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

Hash the server url along with user id #1184

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Fixed displaying object level permissions for the correct object when the table of objects were filtered or sorted. ([#1180](https://github.com/realm/realm-studio/pull/1180))
- Fixed exporting schemas to Java and Kotlin. The @Required annotation was incorrectly applied to lists of non-primitives. ([#1181](https://github.com/realm/realm-studio/pull/1181), since v1.8.0)
- On Windows, ensure there'll be no unnecessary local path collisions when browsing multiple Realm Cloud instances. The effect would have been that Realms with the same name that resided on different servers would need to be redownloaded every time you switched servers. ([#1183](https://github.com/realm/realm-studio/issues/1183), since v3.7.0)

### Internals

Expand Down
28 changes: 17 additions & 11 deletions src/services/ros/realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,24 @@ const getPathOnDisk = (
user: Realm.Sync.User,
realmPath: string,
): string | undefined => {
// Only Windows have path limits, so it's fine to default to whatever OS generates.
// Only Windows has path limits, so it's fine to generate a path from hashes.
if (process.platform === 'win32') {
const userPath = path.join(process.cwd(), user.identity);
fs.ensureDirSync(userPath);

return path.join(
userPath,
crypto
.createHash('md5')
.update(realmPath)
.digest('hex'),
);
const userSegment = crypto
.createHash('md5')
.update(`${user.server}:${user.identity}`)
.digest('hex');

const realmPathSegment = crypto
.createHash('md5')
.update(realmPath)
.digest('hex');

const result = path.join(process.cwd(), userSegment, realmPathSegment);

// Ensure the parent folder exists as Realm doesn't create it automatically
fs.ensureDirSync(path.dirname(result));

return result;
}
};

Expand Down