prevent copy or move of empty file

This commit is contained in:
grimhilt 2023-08-24 22:19:11 +02:00
parent 498fada9ec
commit d476622305
2 changed files with 9 additions and 3 deletions

View File

@ -9,12 +9,11 @@ This should work pretty much like git with some adaptations to be more debuggabl
## Features ## Features
- [x] Cloning - [x] Cloning
- [x] Status (only for new and deleted files/folders) - [x] Status (new, deleted, modified, copied, moved)
- [x] Pushing updates (only deletion and addition no changes) - [x] Pushing updates (new, deleted, modified)
- [x] Using a .nextsyncignore to ignore files - [x] Using a .nextsyncignore to ignore files
- [ ] Pulling changes - [ ] Pulling changes
- [ ] Auth without using env variables - [ ] Auth without using env variables
- [ ] Detecting local changes
- [ ] Various optimisation - [ ] Various optimisation
## Usage ## Usage

View File

@ -12,6 +12,8 @@ use crate::utils::{path, read};
use crate::store::head; use crate::store::head;
use crate::store::object::{update_dates, add_node, rm_node}; use crate::store::object::{update_dates, add_node, rm_node};
const HASH_EMPTY: &str = "d41d8cd98f00b204e9800998ecf8427e";
pub struct Blob { pub struct Blob {
r_path: PathBuf, // relative path r_path: PathBuf, // relative path
a_path: PathBuf, // absolute path a_path: PathBuf, // absolute path
@ -132,6 +134,11 @@ impl Blob {
} }
pub fn get_all_identical_blobs(&mut self) -> Vec<String> { pub fn get_all_identical_blobs(&mut self) -> Vec<String> {
// an empty file is a new file not the copy of another empty file
if self.get_file_hash() == HASH_EMPTY {
return vec![];
}
let refs_p = self.get_file_ref(); let refs_p = self.get_file_ref();
let mut blobs: Vec<String> = vec![]; let mut blobs: Vec<String> = vec![];
if let Ok(lines) = read::read_lines(refs_p) { if let Ok(lines) = read::read_lines(refs_p) {