Skip to content

Make fs::rename on windows obey Unix rename semantics. #1583 #17203

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

Closed
wants to merge 1 commit into from

Conversation

brson
Copy link
Contributor

@brson brson commented Sep 12, 2014

On Unix rename fails if the target directory exists and contains
other files
. For consistency, emulate that behavior on Windows.

cc @alexcrichton

On Unix rename fails if the target directory exists *and contains
other files*. For consistency, emulate that behavior on Windows.
@alexcrichton
Copy link
Member

Interesting, this is even listed in CERT as a possible hazard.

Err(ref e) if e.kind == io::FileNotFound => (/* destination doesn't exist. fine */),
Err(e) => return Err(e.clone())
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I try to move these workarounds to only happen in the error case of fs_rename, that way the "fast path" avoids the extra syscall to stat/readdir/etc.

@alexcrichton
Copy link
Member

Other than shuffling the logic to happen in the error case of fs_rename, r=me

/// the process lacks permissions to view the contents, or if some other
/// intermittent I/O error occurs.
/// the process lacks permissions to view the contents, if `to` both exists *and*
//// is non-empty, or if some other intermittent I/O error occurs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A / too much.

@alexcrichton
Copy link
Member

Closing out of inactivity.

lnicola pushed a commit to lnicola/rust that referenced this pull request May 19, 2024
Fix OOM caused by term search

The issue came from multi Cartesian product for exprs with many (25+) arguments, each having multiple options.
The solution is two fold:
### Avoid blowing up in Cartesian product
**Before the logic was:**
    1. Find expressions for each argument/param - there may be many
    2. Take the Cartesian product (which blows up in some cases)
    4. If there are more than 2 options throw them away by squashing them to `Many`
**Now the logic is:**
    1. Find expressions for each argument/param and squash them to `Many` if there are more than 2 as otherwise we are guaranteed to also have more than 2 after taking the product which means squashing them anyway.
    2. Take the Cartesian product on iterator
    3. Start consuming it one by one
    4. If there are more than 2 options throw them away by squashing them to `Many`  (same as before)

This is also why I had to update some tests as the expressions get squashed to many more eagerly.

### Use fuel to avoid long search times and high memory usage
Now all the tactics use `should_continue:  Fn() -> bool` to chech if they should keep iterating _(Similarly to chalk)_.
This reduces the search times by a magnitude, for example from ~139ms/hole to ~14ms/hole for `ripgrep` crate.
There are slightly less expressions found, but I think speed gain worth it for usability.
Also note that syntactic hits decreases more because of squashing so you simple need to run search multiple times to get full terms.
Also the worst case time (For example `nalgebra` crate cus it has tons of generics) has search times mostly under 200ms.

Benchmarks on `ripgrep` crate
Before:
```
Tail Expr syntactic hits: 291/1692 (17%)
Tail Exprs found: 1253/1692 (74%)
Term search avg time: 139ms
````
After:
```
Tail Expr syntactic hits: 239/1692 (14%)
Tail Exprs found: 1226/1692 (72%)
Term search avg time: 14ms
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants