<commit_before>/*
 * Copyright 2002, 2003,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs.tasks;

import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.Selectors;

/**
 * An Ant task that moves matching files.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 1.7 $ $Date: 2004/02/28 03:35:52 $
 *
 * @todo Delete matching folders
 */
public class MoveTask
    extends CopyTask
{
    /**
     * Handles a single source file.
     */
    protected void handleOutOfDateFile( final FileObject srcFile,
                                        final FileObject destFile )
        throws FileSystemException
    {
        super.handleOutOfDateFile( srcFile, destFile );
        log( "Deleting " + srcFile );
        srcFile.delete( Selectors.SELECT_SELF );
    }
}
<commit_msg>added "tryRename" to allow to rename a file instead of copy/delete it. if rename is not possible the file is copied/deleted anyway.<commit_after>/*
 * Copyright 2002, 2003,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs.tasks;

import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.Selectors;

/**
 * An Ant task that moves matching files.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: 1.8 $ $Date: 2004/05/08 20:05:47 $
 * @todo Delete matching folders
 */
public class MoveTask
    extends CopyTask
{
    private boolean tryRename = false;

    /**
     * Enable/disable move/rename of file (if possible)
     */
    public void setTryRename(boolean tryRename)
    {
        this.tryRename = tryRename;
    }

    /**
     * Handles a single source file.
     */
    protected void handleOutOfDateFile(final FileObject srcFile,
                                       final FileObject destFile)
        throws FileSystemException
    {
        if (!tryRename || !srcFile.canRenameTo(destFile))
        {
            super.handleOutOfDateFile(srcFile, destFile);

            log("Deleting " + srcFile);
            srcFile.delete(Selectors.SELECT_SELF);
        }
        else
        {
            log("Rename " + srcFile + " to " + destFile);
            srcFile.moveTo(destFile);
            if (!isPreserveLastModified())
            {
                destFile.getContent().setLastModifiedTime(System.currentTimeMillis());
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09468114731272625, 'fraction_numerical': 0.017822333611807295, 'mean_word_length': 2.7261410788381744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883404', 'n_tokens_mistral': 1043, 'n_tokens_neox': 984, 'n_words': 331}