-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement synchronization scheme for incr. comp. directory #35718
Merged
bors
merged 11 commits into
rust-lang:master
from
michaelwoerister:incr-comp-dir-locking
Sep 1, 2016
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6ef8198
Move `flock.rs` from librustdoc to librustc_data_structures.
michaelwoerister 206e7b6
Add some features to flock.
michaelwoerister 3e9bed9
Implement copy-on-write scheme for managing the incremental compilati…
michaelwoerister 794fd31
incr.comp.: Move lock files out of directory being locked
michaelwoerister 004a7eb
Fix rustbuild
michaelwoerister b67f57a
incr. comp.: Fix test_timestamp_serialization so it does not overflow…
michaelwoerister a3dc5f9
incr.comp.: Make path's of session directories slightly shorter.
michaelwoerister 9d11068
incr.comp.: Make compiletest generate shorter cache directory names.
michaelwoerister 68d2275
Fix tidy-errors
michaelwoerister 50b008a
compiletest: Canonicalize paths when remove incr.comp. dir, enabling …
michaelwoerister bcd2f90
incr.comp.: Canonicalize path to session directory before deleteing it.
michaelwoerister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,49 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { | |
} | ||
} | ||
|
||
pub enum LinkOrCopy { | ||
Link, | ||
Copy | ||
} | ||
|
||
/// Copy `p` into `q`, preferring to use hard-linking if possible. If | ||
/// `q` already exists, it is removed first. | ||
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<()> { | ||
/// The result indicates which of the two operations has been performed. | ||
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> { | ||
let p = p.as_ref(); | ||
let q = q.as_ref(); | ||
if q.exists() { | ||
try!(fs::remove_file(&q)); | ||
} | ||
fs::hard_link(p, q) | ||
.or_else(|_| fs::copy(p, q).map(|_| ())) | ||
|
||
match fs::hard_link(p, q) { | ||
Ok(()) => Ok(LinkOrCopy::Link), | ||
Err(_) => { | ||
match fs::copy(p, q) { | ||
Ok(_) => Ok(LinkOrCopy::Copy), | ||
Err(e) => Err(e) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Like std::fs::create_dir_all, except handles concurrent calls among multiple | ||
// threads or processes. | ||
pub fn create_dir_racy(path: &Path) -> io::Result<()> { | ||
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. is this just copied from compiletest? 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. It's moved here from |
||
match fs::create_dir(path) { | ||
Ok(()) => return Ok(()), | ||
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => return Ok(()), | ||
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {} | ||
Err(e) => return Err(e), | ||
} | ||
match path.parent() { | ||
Some(p) => try!(create_dir_racy(p)), | ||
None => return Err(io::Error::new(io::ErrorKind::Other, | ||
"failed to create whole tree")), | ||
} | ||
match fs::create_dir(path) { | ||
Ok(()) => Ok(()), | ||
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()), | ||
Err(e) => Err(e), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will be horribly slow on Windows using ReFS filesystems. The CreateHardLink is only supported on the NTFS systems. ReFS supports copy-on-write (read: reflinks), but not hard links, so it is yet another reason to use reflinks if these are supported.
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 can't find any documentation about reflinks on ReFS, so I guess that any copy operation within the same ReFS file system is automatically the equivalent of creating a reflink? In that case, we could just fall back to always copying if the first try of creating a hard-link has failed.
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.
AFAICT simple copy is not reflink on ReFS, sadly.
There’s FSCTL in a Windows Server 2016+ which seems like it should behave like the reflink equivalent for btrfs.
That being said, it also seems like ReFSv1 (which is what you get by default) does not in fact support/expose that operation, so I guess there’s nothing we can do here.
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.
Well, that's a pity
:(
But thanks for the information!