-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Create a shorter temp file name for model loading. #397
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,13 +109,35 @@ internal Repository(bool needDir, IExceptionContext ectx) | |
| _open = new List<Entry>(); | ||
| if (needDir) | ||
| { | ||
| DirTemp = GetTempPath(); | ||
| DirTemp = GetShortTempPath(); | ||
| Directory.CreateDirectory(DirTemp); | ||
| } | ||
| else | ||
| GC.SuppressFinalize(this); | ||
| } | ||
|
|
||
| private static string GetShortTempPath() | ||
| { | ||
| Guid guid = Guid.NewGuid(); | ||
| var guidName = guid.ToString(); | ||
| int index = guidName.IndexOf('-'); | ||
| if (index < 0) | ||
| index = Math.Min(8, guidName.Length); | ||
| guidName = guidName.Substring(0, index); | ||
| var path = Path.Combine(Path.GetTempPath(), "TLC_" + guidName); | ||
| while (Directory.Exists(path)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
why even bother with GUId?, why not just take a random int and convert to hex? That's the shortest and will collide only once in a million times on average (assuming you randomize properly.) #Closed |
||
| { | ||
| guid = Guid.NewGuid(); | ||
| guidName = guid.ToString(); | ||
| index = guidName.IndexOf('-'); | ||
| if (index < 0) | ||
| index = Math.Min(8, guidName.Length); | ||
| guidName = guidName.Substring(0, index); | ||
| path = Path.Combine(Path.GetTempPath(), "TLC_" + guidName); | ||
| } | ||
| return Path.GetFullPath(path); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Back when we were using a GUID this was less likely, but now the likelihood of a collision is much higher, I start to worry a lot more about the inherent race condition in this code. :P With a 128-bit GUID, the chance of collision was on the order of 1/2^64... now it's 31 bits, it's on the order of 1/2^16. Can we restructure this code a bit so that the creation of the directory and the generation of a supposedly safe directory name happen at the same time? We can handle this by creating it in a non-lazy fashion. If we want the creation to be "lazy" as it currently is, then I do not see how the currently scheme of a |
||
| } | ||
|
|
||
| // REVIEW: This should use host environment functionality. | ||
| private static string GetTempPath() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
you can just make do while loop #Resolved