Class Move

  • All Implemented Interfaces:

    public class Move
    extends Copy
    Moves a file or directory to a new file or directory. By default, the destination file is overwritten if it already exists. When overwrite is turned off, then files are only moved if the source file is newer than the destination file, or when the destination file does not exist.

    Source files and directories are only deleted when the file or directory has been copied to the destination successfully. Filtering also works.

    This implementation is based on Arnout Kuiper's initial design document, the following mailing list discussions, and the copyfile/copydir tasks.

    Ant 1.2
    • Constructor Detail

      • Move

        public Move()
        Constructor of object. This sets the forceOverwrite attribute of the Copy parent class to true.
    • Method Detail

      • setPerformGcOnFailedDelete

        public void setPerformGcOnFailedDelete​(boolean b)
        Whether to perform a garbage collection before retrying a failed delete.

        This may be required on Windows (where it is set to true by default) but also on other operating systems, for example when deleting directories from an NFS share.

        b - boolean
        Ant 1.8.3
      • validateAttributes

        protected void validateAttributes()
                                   throws BuildException
        Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes..
        validateAttributes in class Copy
        BuildException - if an error occurs.
      • doFileOperations

        protected void doFileOperations()
        Override copy's doFileOperations to move the files instead of copying them.
        doFileOperations in class Copy
      • okToDelete

        protected boolean okToDelete​( d)
        Its only ok to delete a directory tree if there are no files in it.
        d - the directory to check
        true if a deletion can go ahead
      • deleteDir

        protected void deleteDir​( d)
        Go and delete the directory tree.
        d - the directory to delete
      • deleteDir

        protected void deleteDir​( d,
                                 boolean deleteFiles)
        Go and delete the directory tree.
        d - the directory to delete
        deleteFiles - whether to delete files
      • renameFile

        protected boolean renameFile​( sourceFile,
                                     boolean filtering,
                                     boolean overwrite)
        Attempts to rename a file from a source to a destination. If overwrite is set to true, this method overwrites existing file even if the destination file is newer. Otherwise, the source file is renamed only if the destination file is older than it. Method then checks if token filtering is used. If it is, this method returns false assuming it is the responsibility to the copyFile method.
        sourceFile - the file to rename
        destFile - the destination file
        filtering - if true, filtering is in operation, file will be copied/deleted instead of renamed
        overwrite - if true force overwrite even if destination file is newer than source file
        true if the file was renamed
        Throws: - if an error occurs
        BuildException - if an error occurs