[jcifs] DFS and renameTo...

Michael B Allen miallen at ioplex.com
Thu Aug 16 16:17:02 GMT 2007


On Thu, 16 Aug 2007 10:58:51 +0200
Torben Wölm <torben.wolm at LEGO.com> wrote:

> 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");
>     	}

So renameTo should probably do a conditional exists() call. I'll add
this to the JCIFS TODO.

Mike

-- 
Michael B Allen
PHP Active Directory Kerberos SSO
http://www.ioplex.com/


More information about the jcifs mailing list