From f6f99c41dbd86f85ce816ea8d388e44e04aed6cc Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 27 Oct 2012 16:34:13 +0530 Subject: modified: .bzrignore conversion/ConvertDirectory.java (bug-fix) It is checked whether file "index" is modified since the last conversion. This check was not performed before. conversion/ConvertFile.java Some optimization there. Now we check if the file content is "empty" before we delve into conversion. index/IndexCreator.java # "index" file is created in the directory, if it is not created. # write() renamed to shouldConvert(). The method now returns true when a link is added to 'index' or when the index.html file does not exists. io/ReadFile.java # Exception message for made verbose. todo --- index/IndexCreator.java | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'index') diff --git a/index/IndexCreator.java b/index/IndexCreator.java index fc469ce..f86f03a 100644 --- a/index/IndexCreator.java +++ b/index/IndexCreator.java @@ -33,13 +33,20 @@ public class IndexCreator { // set to true, if index file is modified. boolean modified = false; public IndexCreator(File directory) { - this.directory = directory; - index = new File(directory,"index"); - indexContent = new StringBuilder(); - if(index.exists()) { - indexContent.append(new ReadFile(index). - getContent()); - } + this.directory = directory; + index = new File(directory,"index"); + indexContent = new StringBuilder(); + if(index.exists()) { + indexContent.append(new ReadFile(index). + getContent()); + }else { + try { + index.createNewFile(); + }catch(IOException e) { + throw new RuntimeException("Unable to create file: "+ + index.getAbsolutePath(),e); + } + } } public void add(File file) { String fileName = file.getName(); @@ -53,10 +60,20 @@ public class IndexCreator { modified=true; } } - public boolean write() { + public boolean shouldConvert() { + // we assume that index.html exists. + boolean indexHTMLExists=true; if(modified) new WriteFile(index,indexContent.toString()).write(); - return modified; + // Check for this existence of index.html. + if(!(new File(directory,"index.html").exists())) { + indexHTMLExists=false; + } + /** + * returns true either when 'index' is modified or + * when index.html does not exists. + */ + return (modified || !indexHTMLExists); } public File indexFile() { return index; -- cgit v1.2.3