[jcifs] DFS and renameTo...

Torben Wölm torben.wolm at LEGO.com
Thu Aug 16 08:58:51 GMT 2007


Sorry to bother again...

In the renameTo method of SmbFile, I receive the SmbException "Invalid operation for workgroups..." at line 2021 for a file placed on DFS.

        if( tree.inDfs ) { /* This ensures that each path is
                * resolved independantly to deal with the case where files
                * have the same base path but ultimately turn out to be
                * on different servers because of DFS. It also eliminates
                * manipulating the SMB path which is problematic because
                * there are really two that would need to be prefixed
                * with host and share as DFS requires.
                */
            exists();
            dest.exists();
        }
        if (!tree.equals(dest.tree)) {
            throw new SmbException( "Invalid operation for workgroups, servers, or shares" );
        }


I figured out it's because I call it this way:

    	if (src.exists()) {
    		src.renameTo(new SmbFile(file.getParent(), newName, auth));
    	} else {
    		throw new FileNotFoundException(src + " does not exist");
    	}

This way "src" is resolving its DFS placement at the "exists()" call, and the tree resets its "inDfs" status. The new destination though, is still not resolved and thus the trees are not equal.

I've solved it with this workaround:

    	if (src.exists()) {
    		SmbFile dst = new SmbFile(file.getParent(), newName, auth);
    		dst.exists();
    		src.renameTo(dst);
    	} else {
    		throw new FileNotFoundException(src + " does not exist");
    	}


Kind regards
Torben


More information about the jcifs mailing list