Add debug output in storage backend code
This commit is contained in:
parent
20dc562dee
commit
53a14ea1dc
1 changed files with 17 additions and 0 deletions
|
@ -35,16 +35,20 @@ impl StorageBackend {
|
||||||
|
|
||||||
fn build<M: Module>(rt: &Runtime, m: &M) -> StorageBackend {
|
fn build<M: Module>(rt: &Runtime, m: &M) -> StorageBackend {
|
||||||
let path = rt.get_rtp() + m.name() + "/store";
|
let path = rt.get_rtp() + m.name() + "/store";
|
||||||
|
// TODO: Don't use "/store" but value from configuration
|
||||||
|
debug!("Building StorageBackend for {}", path);
|
||||||
StorageBackend::new(path)
|
StorageBackend::new(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_file_ids(&self) -> Option<Vec<FileID>> {
|
fn get_file_ids(&self) -> Option<Vec<FileID>> {
|
||||||
|
debug!("Getting files from {}", self.basepath);
|
||||||
let list = glob(&self.basepath[..]);
|
let list = glob(&self.basepath[..]);
|
||||||
|
|
||||||
if let Ok(globlist) = list {
|
if let Ok(globlist) = list {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
for entry in globlist {
|
for entry in globlist {
|
||||||
if let Ok(path) = entry {
|
if let Ok(path) = entry {
|
||||||
|
debug!(" - File: {:?}", path);
|
||||||
v.push(from_pathbuf(&path));
|
v.push(from_pathbuf(&path));
|
||||||
} else {
|
} else {
|
||||||
// Entry is not a path
|
// Entry is not a path
|
||||||
|
@ -70,8 +74,10 @@ impl StorageBackend {
|
||||||
if let Ok(string) = written {
|
if let Ok(string) = written {
|
||||||
let path = self.build_filepath(&f);
|
let path = self.build_filepath(&f);
|
||||||
debug!("Writing file: {}", path);
|
debug!("Writing file: {}", path);
|
||||||
|
debug!(" contents: {}", string);
|
||||||
Ok(Ok(()))
|
Ok(Ok(()))
|
||||||
} else {
|
} else {
|
||||||
|
debug!("Error parsing : {:?}", f.contents());
|
||||||
Err(written.err().unwrap())
|
Err(written.err().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,13 +93,17 @@ impl StorageBackend {
|
||||||
let contents = p.write(f.contents());
|
let contents = p.write(f.contents());
|
||||||
|
|
||||||
if contents.is_err() {
|
if contents.is_err() {
|
||||||
|
debug!("Error parsing contents: {:?}", f.contents());
|
||||||
return Err(contents.err().unwrap());
|
return Err(contents.err().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = contents.unwrap();
|
let content = contents.unwrap();
|
||||||
|
debug!("Success parsing content : {}", content);
|
||||||
|
|
||||||
let path = self.build_filepath(&f);
|
let path = self.build_filepath(&f);
|
||||||
|
debug!("Trying to write to file at {}", path);
|
||||||
if let Err(_) = FSFile::open(&path) {
|
if let Err(_) = FSFile::open(&path) {
|
||||||
|
debug!("Error opening {}", path);
|
||||||
return Ok(Err(StorageBackendError::new(
|
return Ok(Err(StorageBackendError::new(
|
||||||
String::from("File::open()"),
|
String::from("File::open()"),
|
||||||
format!("Tried to open '{}'", path),
|
format!("Tried to open '{}'", path),
|
||||||
|
@ -103,6 +113,7 @@ impl StorageBackend {
|
||||||
|
|
||||||
if let Ok(mut file) = FSFile::create(&path) {
|
if let Ok(mut file) = FSFile::create(&path) {
|
||||||
if let Err(writeerr) = file.write_all(&content.clone().into_bytes()) {
|
if let Err(writeerr) = file.write_all(&content.clone().into_bytes()) {
|
||||||
|
debug!("Error writing to {}", path);
|
||||||
return Ok(Err(StorageBackendError::new(
|
return Ok(Err(StorageBackendError::new(
|
||||||
String::from("File::write()"),
|
String::from("File::write()"),
|
||||||
format!("Tried to write '{}'", path),
|
format!("Tried to write '{}'", path),
|
||||||
|
@ -111,6 +122,7 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Successfully written to file.");
|
||||||
Ok(Ok(()))
|
Ok(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,11 +136,15 @@ impl StorageBackend {
|
||||||
pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser<HP>) -> Option<File>
|
pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser<HP>) -> Option<File>
|
||||||
where HP: FileHeaderParser<'a>
|
where HP: FileHeaderParser<'a>
|
||||||
{
|
{
|
||||||
|
debug!("Searching for file with id '{}'", id);
|
||||||
if let Ok(mut fs) = FSFile::open(self.build_filepath_with_id(id.clone())) {
|
if let Ok(mut fs) = FSFile::open(self.build_filepath_with_id(id.clone())) {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
fs.read_to_string(&mut s);
|
fs.read_to_string(&mut s);
|
||||||
|
debug!("Success reading file with id '{}'", id);
|
||||||
|
debug!("Parsing to internal structure now");
|
||||||
p.read(s).and_then(|(h, d)| Ok(File::from_parser_result(id, h, d))).ok()
|
p.read(s).and_then(|(h, d)| Ok(File::from_parser_result(id, h, d))).ok()
|
||||||
} else {
|
} else {
|
||||||
|
debug!("No file with id '{}'", id);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +154,7 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_filepath_with_id(&self, id: FileID) -> String {
|
fn build_filepath_with_id(&self, id: FileID) -> String {
|
||||||
|
debug!("Building filepath for id '{}'", id);
|
||||||
self.basepath.clone() + &id[..]
|
self.basepath.clone() + &id[..]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue