Search in sources :

Example 1 with IgfsInvalidPathException

use of org.apache.ignite.igfs.IgfsInvalidPathException in project ignite by apache.

the class IgfsImpl method rename.

/** {@inheritDoc} */
@Override
public void rename(final IgfsPath src, final IgfsPath dest) {
    A.notNull(src, "src");
    A.notNull(dest, "dest");
    if (meta.isClient()) {
        meta.runClientTask(new IgfsClientRenameCallable(cfg.getName(), IgfsUserContext.currentUser(), src, dest));
        return;
    }
    safeOp(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Rename file [src=" + src + ", dest=" + dest + ']');
            IgfsMode mode = resolveMode(src);
            if (src.equals(dest))
                // Rename to itself is a no-op.
                return null;
            // Cannot rename root directory.
            if (src.parent() == null)
                throw new IgfsInvalidPathException("Root directory cannot be renamed.");
            // Cannot move directory of upper level to self sub-dir.
            if (dest.isSubDirectoryOf(src))
                throw new IgfsInvalidPathException("Failed to rename directory (cannot move directory of " + "upper level to self sub-dir) [src=" + src + ", dest=" + dest + ']');
            if (evictExclude(src, mode == PRIMARY) != evictExclude(dest, modeRslvr.resolveMode(dest) == PRIMARY))
                throw new IgfsInvalidPathException("Cannot move file to a path with different eviction " + "exclude setting (need to copy and remove)");
            switch(mode) {
                case PRIMARY:
                    meta.move(src, dest);
                    break;
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    await(src, dest);
                    meta.renameDual(secondaryFs, src, dest);
                    break;
                default:
                    assert mode == PROXY : "Unknown mode: " + mode;
                    secondaryFs.rename(src, dest);
                    break;
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientRenameCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientRenameCallable) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgfsException (org.apache.ignite.igfs.IgfsException)1 IgfsInvalidPathException (org.apache.ignite.igfs.IgfsInvalidPathException)1 IgfsMode (org.apache.ignite.igfs.IgfsMode)1 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)1 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)1 IgfsClientRenameCallable (org.apache.ignite.internal.processors.igfs.client.IgfsClientRenameCallable)1