Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with the Mirroring of Files  RSS feed

 
K Man
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I created a Java application that enables the mirroring of files (and directories) from one directory to another directory. I got it to work but the problem is when it "mirrors" it recopies and deletes files in the process. It is copying directories it doesnt need to in the process (it is overriding identical directories with same modification times and recopying unneccesarily). On big file systems this would be slow, and I have been told to fix this. I tried adding in the conditional that if the modification times on the directories were the same, then dont copy but it is not working for me. COuld somebody help me out with this? I have attached code for three methods: mirrorFiles, copy, and copyDirectory thanks,
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setLastModified can fail, depending on the OS, filesystem, and your permissions. It returns boolean to indicate whether it succeeded or not, and you're not checking the return values, so what I'd recommend would be for you to add these checks.
Actually, a better thing to do would be to remove the setLastModified() calls altogether, and change your conditions to check for the mirror's mod time being less than the original's mod time, rather than checking for equality.
 
K Man
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,
Thanks for your reply. I will try what you said and post if I have any further questions.
Thanks,
-K Man
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!