Skip to content

Instantly share code, notes, and snippets.

@Yoric
Created May 29, 2012 08:00
Show Gist options
  • Save Yoric/2823196 to your computer and use it in GitHub Desktop.
Save Yoric/2823196 to your computer and use it in GitHub Desktop.
Function |move|, in Rust (take 1)
fn move(from: string, to: string, options: move_options, policy: issue_policy): bool {
// Handle options.no_overwrite
if (options.no_overwrite) {
alt(file::open(to, O_WRONLY, 0, report_error_as_sum)) {
{ok} {
close(ok, ignore_error); // Could be removed with some RAII mechanism
}
{ko: {errno}} if errno == EACCESS {
ret policy.report(/*destination exists*/);
}
{ko: {errno}} {
// Do nothing
}
x {
// Any other kind of error
ret policy.report(x);
}
}
}
// Attempt to rename file
alt (file::rename(from, to, report_error_as_sum)) {
{ok} { ret policy.success(ok); }
{ko: {errno}} if errno != EXDEV {
ret policy.report({errno: errno});
}
_ {}
}
file::copy(from, to, propagate_error);
file::remove(from, propagate_error);
ret policy.success();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment