Skip to content

Commit

Permalink
fix rust compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
derdilla committed Jul 1, 2024
1 parent ab23723 commit b4f0dff
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
5 changes: 3 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
resolver = "2"

members = [
"dir_size", "ini-conf", "vcs",
"dir_size", "iniconf", "vcs",
]
4 changes: 2 additions & 2 deletions rust/ini-conf/Cargo.toml → rust/iniconf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ini-conf"
version = "0.1.0"
name = "iniconf"
version = "1.0.0"
edition = "2021"

[dependencies]
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions rust/vcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
[dependencies]
clap = { version = "4.5.8", features = ["derive"] }
log = "0.4.22"
iniconf = { path = "../iniconf", version = "1.0.0"}
62 changes: 32 additions & 30 deletions rust/vcs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iniconf::IniFile;
use std::{fs, os};
use std::fs::{create_dir, create_dir_all};
use std::path::{Path, PathBuf};
use log::{log, warn};

Expand Down Expand Up @@ -47,41 +47,42 @@ impl Repository {
}

pub fn init(path: PathBuf) -> Result<Self, RepositoryInitError> {
let repo = Self::new(path, Some(true)).ok().expect("Force is passed");
let mut repo = Self::new(path, Some(true)).ok().expect("Force is passed");
if repo.work_tree.is_file() || repo.work_tree.is_symlink() {
Err(RepositoryInitError::NotADirectory)
} else if repo.git_dir.read_dir().is_ok_and(|dir| dir.count() > 0) {
Err(RepositoryInitError::AlreadyInitialized)
} else {
let success: Option<()> = {
if !repo.git_dir.exists() {
create_dir_all(&repo.git_dir).ok()?;
}

repo.repo_path(vec!["branches"], Some(true), Some(false))?;
repo.repo_path(vec!["objects"], Some(true), Some(false))?;
repo.repo_path(vec!["refs", "tags"], Some(true), Some(false))?;
repo.repo_path(vec!["refs", "heads"], Some(true), Some(false))?;

let desc = repo.repo_path(vec!["description"], Some(false), Some(true))?;
fs::write(desc, "Unnamed repository; edit this file 'description' to name the repository.\n")?;

let head = repo.repo_path(vec!["HEAD"], Some(false), Some(true))?;
fs::write(head, "ref: refs/heads/master\n")?;

let config = repo.repo_path(vec!["config"], Some(false), Some(true))?;
repo.config.write(config)?;

Some(())
};
if success.is_none() {
if Self::init_fs(&mut repo).is_none() {
Err(RepositoryInitError::IOError)
} else {
Ok(repo)
}
}
}

fn init_fs(repo: &mut Repository) -> Option<()> {
if !repo.git_dir.exists() {
fs::create_dir_all(&repo.git_dir).ok()?;
}

repo.repo_path(vec!["branches"], Some(true), Some(false))?;
repo.repo_path(vec!["objects"], Some(true), Some(false))?;
repo.repo_path(vec!["refs", "tags"], Some(true), Some(false))?;
repo.repo_path(vec!["refs", "heads"], Some(true), Some(false))?;

let desc = repo.repo_path(vec!["description"], Some(false), Some(true))?;
fs::write(desc, "Unnamed repository; edit this file 'description' to name the repository.\n").ok()?;

let head = repo.repo_path(vec!["HEAD"], Some(false), Some(true))?;
fs::write(head, "ref: refs/heads/master\n").ok()?;

let config = repo.repo_path(vec!["config"], Some(false), Some(true))?;
repo.config.write(config)?;

Some(())
}

/// Compute path under repo's gitdir.
///
/// If [mkdir] is true directories specified in the path will be created.
Expand All @@ -107,10 +108,10 @@ impl Repository {
}
if mkdir {
if res_path.exists() && !res_path.is_dir() {
panic!("Tried to create dir where there already was a file: {}", &res_path);
panic!("Tried to create dir where there already was a file: {:?}", &res_path);
}
if std::fs::create_dir_all(&res_path).is_err() {
warn!("Failed to create {}", &res_path);
if fs::create_dir_all(&res_path).is_err() {
warn!("Failed to create {:?}", &res_path);
}
}

Expand All @@ -126,7 +127,7 @@ impl Repository {
}

#[derive(Debug)]
enum RepositoryLoadError {
pub enum RepositoryLoadError {
NotAGitRepository,
ConfigurationFileMissing,
UnsupportedRepositoryFormatVersion {
Expand All @@ -138,7 +139,7 @@ enum RepositoryLoadError {
}

#[derive(Debug)]
enum RepositoryInitError {
pub enum RepositoryInitError {
NotADirectory,
AlreadyInitialized,
IOError,
Expand All @@ -158,6 +159,7 @@ struct RepoConfig {
}
impl RepoConfig {
fn read(path: PathBuf) -> Self {
//IniFile::open(path)
Self::default() // TODO
}

Expand All @@ -168,7 +170,7 @@ impl RepoConfig {
self.bare,
);

fs::write(path, txt)?;
fs::write(path, txt).ok()?;

Some(())
}
Expand Down

0 comments on commit b4f0dff

Please sign in to comment.