| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2008 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.tools; |
| 17 | |
| 18 | import java.io.File; |
| 19 | |
| 20 | import net.sf.wraplog.Logger; |
| 21 | |
| 22 | /** |
| 23 | * Task to recursively copy all files and directories in <code>newSourceDir</code> to <code>newTargetDir</code> |
| 24 | * . |
| 25 | * |
| 26 | * @author Thomas Aglassinger |
| 27 | */ |
| 28 | public class CopyDirTask extends NestedTask |
| 29 | { |
| 30 | private boolean allCopied; |
| 31 | private FileTools fileTools; |
| 32 | private Logger logger = Logger.getLogger(CopyDirTask.class); |
| 33 | private File targetDir; |
| 34 | |
| 35 | public CopyDirTask(File newSourceDir, File newTargetDir) { |
| 36 | this(newTargetDir, FileTools.instance().createCopyDirTasks(newSourceDir, newTargetDir)); |
| 37 | } |
| 38 | |
| 39 | private CopyDirTask(File newTargetDir, CopyFileTask[] copyFileTasks) { |
| 40 | super(copyFileTasks); |
| 41 | fileTools = FileTools.instance(); |
| 42 | targetDir = newTargetDir; |
| 43 | } |
| 44 | |
| 45 | public void start() |
| 46 | throws Exception { |
| 47 | allCopied = false; |
| 48 | try { |
| 49 | start(); |
| 50 | allCopied = true; |
| 51 | } finally { |
| 52 | if (!allCopied) { |
| 53 | fileTools.attemptToDeleteAll(targetDir, logger); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |