Skip to content

Commit

Permalink
Merge pull request libfuse#6 from quark-zju/windows
Browse files Browse the repository at this point in the history
Various Windows fixes
  • Loading branch information
martinvonz committed Mar 15, 2021
2 parents 5631e85 + 0fb59a5 commit 6a2bb46
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,29 @@
name: build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-latest ]

steps:
- uses: actions/checkout@v2
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
profile: minimal
- name: Build
run: |
cargo build --workspace --verbose
- name: Test
run: |
cargo test --workspace --verbose
3 changes: 3 additions & 0 deletions lib/src/lock.rs
Expand Up @@ -36,6 +36,9 @@ impl FileLock {
Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => {
Err(backoff::Error::Transient(err))
}
Err(err) if cfg!(windows) && err.kind() == std::io::ErrorKind::PermissionDenied => {
Err(backoff::Error::Transient(err))
}
Err(err) => Err(backoff::Error::Permanent(err)),
};
let mut backoff = ExponentialBackoff {
Expand Down
16 changes: 16 additions & 0 deletions lib/src/working_copy.rs
Expand Up @@ -254,7 +254,10 @@ impl TreeState {
} else if metadata_file_type.is_symlink() {
FileType::Symlink
} else {
#[cfg(unix)]
let mode = metadata.permissions().mode();
#[cfg(windows)]
let mode = 0;
if mode & 0o111 != 0 {
FileType::Executable
} else {
Expand Down Expand Up @@ -289,6 +292,19 @@ impl TreeState {
let git_repo_dir = tempfile::tempdir().unwrap();
let mut git_repo_options = RepositoryInitOptions::new();
git_repo_options.workdir_path(&self.working_copy_path);
// Repository::init_opts creates a ".git" file in the working copy,
// which is undesired. On Windows it's worse because that ".git" makes
// the next Repository::init_opts fail with "Permission Denied".
// Automatically remove it.
let _cleanup_dot_git = {
struct Cleanup(PathBuf);
impl Drop for Cleanup {
fn drop(&mut self) {
let _ = fs::remove_file(&self.0);
}
}
Cleanup(self.working_copy_path.join(".git"))
};
let git_repo = Repository::init_opts(git_repo_dir.path(), &git_repo_options).unwrap();

let mut work = vec![(DirRepoPath::root(), self.working_copy_path.clone())];
Expand Down
2 changes: 2 additions & 0 deletions lib/tests/test_commit_concurrent.rs
Expand Up @@ -36,6 +36,7 @@ fn count_non_merge_operations(repo: &ReadonlyRepo) -> u32 {
num_ops
}

#[cfg(unix)]
#[test_case(false ; "local store")]
#[test_case(true ; "git store")]
fn test_commit_parallel(use_git: bool) {
Expand Down Expand Up @@ -68,6 +69,7 @@ fn test_commit_parallel(use_git: bool) {
assert_eq!(count_non_merge_operations(&repo), 101);
}

#[cfg(unix)]
#[test_case(false ; "local store")]
#[test_case(true ; "git store")]
fn test_commit_parallel_instances(use_git: bool) {
Expand Down
3 changes: 3 additions & 0 deletions lib/tests/test_working_copy.rs
Expand Up @@ -50,6 +50,7 @@ fn test_root(use_git: bool) {
assert_eq!(wc_commit.committer().email, settings.user_email());
}

#[cfg(unix)]
#[test_case(false ; "local store")]
#[test_case(true ; "git store")]
fn test_checkout_file_transitions(use_git: bool) {
Expand Down Expand Up @@ -195,6 +196,7 @@ fn test_checkout_file_transitions(use_git: bool) {
assert_eq!(maybe_metadata.is_ok(), true, "{:?} should exist", path);
let metadata = maybe_metadata.unwrap();
assert_eq!(metadata.is_file(), true, "{:?} should be a file", path);
#[cfg(unix)]
assert_eq!(
metadata.permissions().mode() & 0o111,
0,
Expand All @@ -206,6 +208,7 @@ fn test_checkout_file_transitions(use_git: bool) {
assert_eq!(maybe_metadata.is_ok(), true, "{:?} should exist", path);
let metadata = maybe_metadata.unwrap();
assert_eq!(metadata.is_file(), true, "{:?} should be a file", path);
#[cfg(unix)]
assert_ne!(
metadata.permissions().mode() & 0o111,
0,
Expand Down
6 changes: 5 additions & 1 deletion src/commands.rs
Expand Up @@ -615,7 +615,11 @@ fn cmd_init(
} else {
repo = ReadonlyRepo::init_local(ui.settings(), wc_path);
}
writeln!(ui, "Initialized repo in {:?}", repo.working_copy_path());
writeln!(
ui,
"Initialized repo in \"{}\"",
repo.working_copy_path().display()
);
Ok(())
}

Expand Down
6 changes: 4 additions & 2 deletions tests/test_init_command.rs
Expand Up @@ -51,10 +51,12 @@ fn test_init_git_external() {
assert!(repo_path.join(".jj").is_dir());
let store_file_contents = std::fs::read_to_string(repo_path.join(".jj").join("store")).unwrap();
assert!(store_file_contents.starts_with("git: "));
assert!(store_file_contents.ends_with("/git-repo"));
assert!(store_file_contents
.replace('\\', "/")
.ends_with("/git-repo"));
assert_eq!(
output.stdout_string(),
format!("Initialized repo in \"{}\"\n", repo_path.to_str().unwrap())
format!("Initialized repo in \"{}\"\n", repo_path.display())
);
}

Expand Down

0 comments on commit 6a2bb46

Please sign in to comment.