[jcifs] Re: SmbFile.delete

Koji seaslug at hotmail.co.jp
Wed Aug 17 07:09:42 GMT 2005


>From: Michael B Allen <mba2000 at ioplex.com> 
>To: Koji <seaslug at hotmail.co.jp> 
>CC: jcifs at lists.samba.org 
>Subject: Re: [jcifs] Re: SmbFile.delete 
>Date: Tue, 16 Aug 2005 13:46:18 -0400 
>
>On Tue, 16 Aug 2005 09:53:07 +0000 (UTC) 
>Koji <seaslug at hotmail.co.jp> wrote: 
>> 
>> My problem is file.exists() returns true but file.delete() fails with 
>> "jcifs.smb.SmbException: The system cannot find the path specified.". 
>
>I don't know then. The only thing I can think of is that you have some 
>Japanese characters somewhere and it's breaking the URL. What is the 
>local encoding on your workstation and what encoding is the server? Are 
>they both Unicode? 
>
>> By the way, I found another fact. 
>> When I can delete the file successfully, the filename parameter in the 
>> request of queryPath is "\folder\filename.ext" which is same as the 
>> filename parameter in request of delete. 
>> And in falure case, the filename parameter of queryPath is 
>> "\server\sharedFolder\folder\filename.ext" 
>
>Yeah, this is wrong. The server and share part should not be there. The 
>URL is getting messed up somewhere internally. At this point I can't 
>really do anyting without a capture [1]. 
>
>Mike 
>
>[1] http://jcifs.samba.org/capture.html 

Sorry, Currently I don't have accessible Linux or NetMon. So I can't send you 
the captured packets. 

But I found out one more thing. 
In failure case, the file to be deleted is in DFS(Distributed File System, not 
Duty Free Shop). 

And if the file is in DFS, the filename parameter of queryPath is modified 
at SmbTree.java:90. So the filename parameter of queryPath contains the server 
and share part. In other hand, SmbComDelete class has own filename parameter, 
and used it as filename parameter of CIFS request message. So the filename 
parameter is not modified. 

When I modified the source code of SmbComDelete like following, delete file 
goes successfully. 

   SmbComDelete( String fileName ) { 
       this.fileName = fileName; 
       this.path = fileName;     // <- add 
       command = SMB_COM_DELETE; 
       searchAttributes = ATTR_HIDDEN | ATTR_HIDDEN | ATTR_SYSTEM; 
   } 

   int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 
       writeInt2( searchAttributes, dst, dstIndex ); 
       return 2; 
   } 
   int writeBytesWireFormat( byte[] dst, int dstIndex ) { 
       int start = dstIndex; 

       dst[dstIndex++] = (byte)0x04; 
       // dstIndex += writeString( fileName, dst, dstIndex ); //<- remove 
       dstIndex += writeString( path, dst, dstIndex );  //<- add 
              return dstIndex - start; 
   } 

I still not understand why the server and share part is added to filename 
parameter in case of DFS, but it goes well. 

And one more thing. 
In the test of delete, now I use URL without Japanese characters. 
In other tests, like listFile, getOutputSteam, or mkdir works well even if 
the URL contains Japanese characters. 

Thanks for your patience of understanding my poor English. 
Koji.  




More information about the jcifs mailing list