-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e067d7b
commit 46f2be8
Showing
13 changed files
with
162 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{fs::{File, OpenOptions}, path::PathBuf}; | ||
use crate::internal::git::repo; | ||
use std::io::prelude::*; | ||
|
||
pub fn add_gitignore_entry(git_dir: &PathBuf, path: &PathBuf) -> Result<(), std::io::Error> { | ||
// get relative path | ||
let ignore_entry_temp = match repo::get_relative_path(git_dir, path) { | ||
Ok(entry) => entry, | ||
Err(e) => return Err(e) | ||
}; | ||
// Add leading slash | ||
let path = ignore_entry_temp.display().to_string(); | ||
let ignore_entry = format!("/{path}"); | ||
|
||
// open the gitignore file, creating one if it doesn't exist | ||
let ignore_file = git_dir.join(".gitignore"); | ||
if !ignore_file.exists() { | ||
File::create(&ignore_file).expect("gitignore cannot be created"); | ||
} | ||
let contents = std::fs::read_to_string(&ignore_file).unwrap(); | ||
if !contents.contains(&ignore_entry) { | ||
let mut file = OpenOptions::new() | ||
.write(true) | ||
.append(true) | ||
.open(ignore_file) | ||
.unwrap(); | ||
|
||
if let Err(e) = writeln!(file, "\n\n# Devious entry\n{ignore_entry}" ) { | ||
eprintln!("Couldn't write to file: {}", e); | ||
} | ||
|
||
} // add ignore entry | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod repo; | ||
pub mod repo; | ||
pub mod ignore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::time::SystemTime; | ||
use std::path::PathBuf; | ||
use std::fs::File; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Result; | ||
use std::fs; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Metadata { | ||
pub file_hash: String, | ||
pub file_size: u64, | ||
pub time_stamp: SystemTime, | ||
pub message: String, | ||
pub group: String, | ||
pub saved_by: String | ||
} | ||
|
||
// static FILE_EXTENSION: String = String::from(".dvsmeta"); | ||
|
||
pub fn save(metadata: &Metadata, path: &PathBuf) -> Result<()> { | ||
// compose path file/to/file.ext.dvsmeta | ||
let metadata_file_path = PathBuf::from(path.display().to_string() + ".dvsmeta"); | ||
|
||
// create file | ||
File::create(&metadata_file_path); | ||
|
||
// write to json | ||
let contents = serde_json::to_string(&metadata).unwrap(); | ||
fs::write(&metadata_file_path, contents); | ||
Ok(()) | ||
} | ||
|
||
pub fn load(path: PathBuf) -> Result<Metadata> { | ||
let contents = fs::read_to_string(path).unwrap(); | ||
let metadata_file: Metadata = serde_json::from_str(&contents)?; | ||
|
||
return Ok(metadata_file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters