Skip to content
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

Windows fix #242

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/lib/src/api/local/branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ mod tests {
// Make a dir
let dir_path = Path::new("test_dir");
let dir_repo_path = repo.path.join(dir_path);
util::fs::create_dir_all(&dir_repo_path)?;
util::fs::create_dir_all(dir_repo_path)?;

// File in the dir
let file_path = dir_path.join(Path::new("test_file.txt"));
Expand All @@ -474,7 +474,7 @@ mod tests {

// New file in root
let file_path_2 = Path::new("test_file_2.txt");
let file_repo_path_2 = repo.path.join(&file_path_2);
let file_repo_path_2 = repo.path.join(file_path_2);
util::fs::write_to_path(&file_repo_path_2, "test")?;

// Add the file
Expand All @@ -483,9 +483,9 @@ mod tests {

// Now modify both files, add a third
let file_path_3 = Path::new("test_file_3.txt");
let file_repo_path_3 = repo.path.join(&file_path_3);
let file_repo_path_3 = repo.path.join(file_path_3);

util::fs::write_to_path(&file_repo_path_3, "test 3")?;
util::fs::write_to_path(file_repo_path_3, "test 3")?;
util::fs::write_to_path(&file_repo_path_2, "something different now")?;
util::fs::write_to_path(&file_repo_path, "something different now")?;

Expand All @@ -494,22 +494,16 @@ mod tests {

let commit_3 = command::commit(&repo, "adding test file 2")?;

let branch = api::local::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap();
let _branch = api::local::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap();

let file_versions =
api::local::branches::list_entry_versions_on_branch(&repo, "main", &file_path)?;

let file_2_versions = api::local::branches::list_entry_versions_on_branch(
&repo,
"main",
&file_path_2.to_path_buf(),
)?;
let file_2_versions =
api::local::branches::list_entry_versions_on_branch(&repo, "main", file_path_2)?;

let file_3_versions = api::local::branches::list_entry_versions_on_branch(
&repo,
"main",
&file_path_3.to_path_buf(),
)?;
let file_3_versions =
api::local::branches::list_entry_versions_on_branch(&repo, "main", file_path_3)?;

assert_eq!(file_versions.len(), 2);
assert_eq!(file_versions[0].0.id, commit_3.id);
Expand Down Expand Up @@ -549,8 +543,8 @@ mod tests {

// Add an irrelevant file - aka this isn't changing for commit 3
let file_path_2 = Path::new("test_file_2.txt");
let file_repo_path_2 = repo.path.join(&file_path_2);
util::fs::write_to_path(&file_repo_path_2, "test")?;
let file_repo_path_2 = repo.path.join(file_path_2);
util::fs::write_to_path(file_repo_path_2, "test")?;
command::add(&repo, &repo.path)?;
let _commit_3 = command::commit(&repo, "adding test file 3")?;

Expand Down Expand Up @@ -578,8 +572,8 @@ mod tests {
command::add(&repo, &repo.path)?;
let commit_6 = command::commit(&repo, "adding test file 6")?;

let main = api::local::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap();
let branch = api::local::branches::get_by_name(&repo, "test_branch")?.unwrap();
let _main = api::local::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap();
let _branch = api::local::branches::get_by_name(&repo, "test_branch")?.unwrap();
let main_versions =
api::local::branches::list_entry_versions_on_branch(&repo, "main", &file_path)?;

Expand Down
11 changes: 10 additions & 1 deletion src/lib/src/api/remote/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,20 @@ pub async fn download_commit_entries_db_to_path(
util::fs::remove_dir_all(&full_unpacked_path)?;
} else {
log::debug!("{} creating {:?}", current_function!(), full_unpacked_path);
std::fs::create_dir_all(&full_unpacked_path)?;
if let Some(parent) = full_unpacked_path.parent() {
std::fs::create_dir_all(parent)?;
} else {
log::error!(
"{} no parent found for {:?}",
current_function!(),
full_unpacked_path
);
}
}

// Move the tmp path to the full path
log::debug!("renaming {:?} to {:?}", tmp_path, full_unpacked_path);

std::fs::rename(
tmp_path.join(HISTORY_DIR).join(commit_id),
&full_unpacked_path,
Expand Down
14 changes: 7 additions & 7 deletions src/lib/src/core/index/commit_dir_entry_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ impl CommitDirEntryReader {

pub fn has_file<P: AsRef<Path>>(&self, path: P) -> bool {
let full_path = self.dir.join(path.as_ref());
let path_hash_prefix = util::hasher::hash_path(&full_path)[0..2].to_string();
let path_hash_prefix = util::hasher::hash_path(full_path)[0..2].to_string();

log::debug!(
"has_file looking for this path hash prefix {:?} for {:?}",
path_hash_prefix,
full_path
);
// log::debug!(
// "has_file looking for this path hash prefix {:?} for {:?}",
// path_hash_prefix,
// full_path
// );

// Binary search for the appropriate vnode
let vnode_child = self
Expand Down Expand Up @@ -177,7 +177,7 @@ impl CommitDirEntryReader {
return false;
};

log::debug!("has_file found file {:?}", file);
// log::debug!("has_file found file {:?}", file);

matches!(file, TreeObjectChild::File { .. })
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/core/index/entry_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ impl EntryIndexer {
entries.par_iter().for_each(|entry| {
let filepath = self.repository.path.join(entry.path());
if versioner::should_unpack_entry(entry, &filepath) {
log::debug!("pull_entries_for_commit unpack {:?}", entry.path());
// log::debug!("pull_entries_for_commit unpack {:?}", entry.path());
let version_path = util::fs::version_path_for_entry(&self.repository, entry);
match util::fs::copy_mkdir(version_path, &filepath) {
Ok(_) => {}
Expand Down Expand Up @@ -919,7 +919,7 @@ impl EntryIndexer {
})
})
{
log::debug!("cleanup_removed_entries : {:?}", dir_entry_result);
// log::debug!("cleanup_removed_entries : {:?}", dir_entry_result);
match dir_entry_result {
Ok(dir_entry) => {
if let Some(was_removed) = &dir_entry.client_state {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/src/core/index/puller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn pull_entries(
}

let missing_entries = get_missing_entries(entries, &dst);
log::debug!("Pulling missing entries {:?}", missing_entries);
// log::debug!("Pulling missing entries {:?}", missing_entries);

if missing_entries.is_empty() {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion tests/test_push_pull.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use liboxen::api;
use liboxen::api::remote;

use liboxen::command;
use liboxen::constants;
use liboxen::constants::DEFAULT_BRANCH_NAME;
Expand Down