amit170394 / sardine

Automatically exported from code.google.com/p/sardine
0 stars 0 forks source link

sardine misinterprets content-type of first sub-directory #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I'm trying to recursively output an entire directory tree like so:

    public static void showDirectoryStructure(Sardine sardine, String url, String prefix) {
        try {
            List<DavResource> resources = sardine.getResources(url);
            for (DavResource res : resources) {
                //Logger.getLogger(Main.class.getName()).log(Level.INFO, res.toString(), res.getName());
                if (res.isDirectory() && !res.isCurrentDirectory()) {

                    System.out.println(prefix + res.getName());

                    showDirectoryStructure(sardine, res.getAbsoluteUrl(), "-" + prefix);
                }
            }
        } catch (SardineException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

The first sub-directory is not output since it's content-type is set to 
text/html:

DavResource [baseUrl=http://localhost/uploads/commons-codec-1.4/, 
contentLength=0, 
contentType=text/html, creation=Wed Feb 24 01:31:56 CET 2010, modified=Thu Aug 
06 
18:42:40 CEST 2009, name=apidocs, nameDecoded=apidocs, 
getAbsoluteUrl()=http://localhost/uploads/commons-codec-1.4/apidocs, 
isDirectory()=false]

What is the expected output? What do you see instead?

Expected Output:
- commons-codec-1.4
-- apidocs

Actual Output:
- commons-codec-1.4

What version of the product are you using? On what operating system?
Version 80 on Mac OS X 10.6.2

Please provide any additional information below.

Original issue reported on code.google.com by christop...@gmail.com on 24 Feb 2010 at 7:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I see you deleted your comment after making the issue. I'm not really sure if 
this is an issue or not. Sardine is just 
regurgitating what comes back from the server. If isDirectory() is failing 
because of the wrong content type is 
being sent back from the server, I'm not really sure what I can do here. 
Thoughts?

Original comment by latch...@gmail.com on 24 Feb 2010 at 7:54

GoogleCodeExporter commented 9 years ago
I deleted the comment since I had made a typo that rendered my comment 
confusing. I did so with the intention of further explaining the problem in a 
new comment. I 
simply did not have the time to do it until now.

I think that there might be an issue in sardine, but I'm not too sure. I'll try 
to explain it:

Let's assume the following directory structure:

/web-dav-root
  /foo
  /bar

Directory foo contains a file called index.html which is displayed when I open 
the file in a browser. However, when I browse the same structure using a WebDAV 
client 
(Cyberduck in my case) foo is displayed as a directory whose content can be 
browsed - which is absolutely correct. If I 'browse' the same structure using 
sardine, sardine 
tells me that /web-dav-root contains the following:

- File foo of type text/html
- Directory bar

Which is not what I would expect. My question is: why is Cyberduck able to 
correctly identify foo as being a directory while sardine is not?

I hope you can understand my reasoning.

By the way, I think that a lot of users and server-admins would appreciate if 
sardine identified itself correctly by sending a user-agent header.

Regards 
Chris

Original comment by christop...@gmail.com on 24 Feb 2010 at 9:04

GoogleCodeExporter commented 9 years ago
which server webdav implementation are you hitting? i think it could be related 
to that. i'm using apache 2.2 
as my reference server.

cyberduck may be 'guessing/assuming' that if a url ends with a / that it is a 
directory. 

i could probably add the same logic to sardine, but at some level, i see that 
as incorrect because your server is 
returning a file (index.html), not a directory listing for that request.

on my servers, i don't have index.html, so this hasn't come up as an issue.

i've filed another issue with regards to the user-agent.

Original comment by latch...@gmail.com on 24 Feb 2010 at 9:18

GoogleCodeExporter commented 9 years ago
I run Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.8h DAV/2 PHP/5.2.6 (XAMPP 
for Mac OS X 0.7.4)

Here's my WebDAV configuration, the last part is why I was asking for the 
user-agent, maybe that 'redirect-carefully' might solve my problem. 

#
# Distributed authoring and versioning (WebDAV)
#
# Required modules: mod_dav, mod_dav_fs, mod_setenvif, mod_alias
#                   mod_auth_digest, mod_authn_file
#

# The following example gives DAV write access to a directory called
# "uploads" under the ServerRoot directory.
#
# The User/Group specified in httpd.conf needs to have write permissions
# on the directory where the DavLockDB is placed and on any directory where
# "Dav On" is specified.

DavLockDB "/Applications/xampp/xamppfiles/var/DavLock"

Alias /uploads "/Applications/xampp/xamppfiles/uploads"

<Directory "/Applications/xampp/xamppfiles/uploads">
    Dav On

    AllowOverride None
    Options None

    Order Allow,Deny
    Allow from all

</Directory>

#
# The following directives disable redirects on non-GET requests for
# a directory that does not include the trailing slash.  This fixes a 
# problem with several clients that do not appropriately handle 
# redirects for folders with DAV methods.
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" 
redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

Original comment by christop...@gmail.com on 24 Feb 2010 at 9:44

GoogleCodeExporter commented 9 years ago
Oh right, I missed that. You specifically need to put the trailing / onto 
requests for directories. if you don't do 
that, then that is against the directions for sardine. by default, sardine does 
not add that trailing slash to getAbsoluteUrl() output.

I'm curious what happens if you change your line to look like this:

                    showDirectoryStructure(sardine, res.getAbsoluteUrl() + "/", "-" + prefix);

Original comment by latch...@gmail.com on 24 Feb 2010 at 10:22

GoogleCodeExporter commented 9 years ago
Nevermind, I looked up the WebDAV specification and I'm pretty convinced that 
this is not a bug.

I set the DirectoryIndex to some next-to-impossible value and it works just 
fine, here's my new httpd.conf:

DavLockDB "/Applications/xampp/xamppfiles/var/DavLock"

Alias /uploads "/Applications/xampp/xamppfiles/uploads"

<Directory "/Applications/xampp/xamppfiles/uploads">
    Dav On

    DirectoryIndex x714b973e98d47ec2df6d5e1486019f22x.x0eb3ca0c8f7e6bc4ae1ee8c2f284d41x

    AllowOverride None
    Options None

    Order Allow,Deny
    Allow from all

</Directory>

Many thanks you for your help!
Chris

Original comment by christop...@gmail.com on 24 Feb 2010 at 10:50

GoogleCodeExporter commented 9 years ago
Yes, that will work as well. =)

Original comment by latch...@gmail.com on 24 Feb 2010 at 10:52

GoogleCodeExporter commented 9 years ago
this is really invalid.

Original comment by latch...@gmail.com on 24 Feb 2010 at 11:02

GoogleCodeExporter commented 9 years ago
Hello there, SVN reports the content-type for directories as "text/html" (see 
https://svn.java.net/svn/hudson~svn/tags/jswidgets-1.5/ e.g.). However I think 
all resources where the resourcetype is set to collection should be treated as 
directories. As a workaround you could do sth. like:
https://github.com/mfriedenhagen/sardine/blob/master/src/main/java/com/googlecod
e/sardine/SardineImpl.java#L263
and set the content-type explicitely to httpd/unix-directory as in
https://github.com/mfriedenhagen/sardine/blob/master/src/main/java/com/googlecod
e/sardine/SardineImpl.java#L289
though I think you should probably introduce a boolean is directory and not 
deduce diretoryveness from content-type only.

Original comment by mfriedenhagen on 14 Dec 2010 at 10:29