throws DavException
{
File resource = checkDavResourceIsArchivaDavResource( member ).getLocalResource();
-
- if ( !resource.exists() )
- {
- throw new DavException( HttpServletResponse.SC_NOT_FOUND, member.getResourcePath() );
- }
-
- boolean suceeded = false;
-
- if ( resource.isDirectory() )
+
+ if ( resource.exists() )
{
try
{
- FileUtils.deleteDirectory( resource );
- suceeded = true;
+ if ( resource.isDirectory() )
+ {
+ FileUtils.deleteDirectory(resource);
+ }
+ else
+ {
+ if (!resource.delete())
+ {
+ throw new IOException("Could not remove file");
+ }
+ }
}
catch ( IOException e )
{
- throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
+ throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
}
}
-
- if ( !suceeded && resource.isFile() )
- {
- suceeded = resource.delete();
- }
-
- if ( !suceeded )
- {
- throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete resource " +
- member.getResourcePath() );
- }
}
public void move( DavResource destination )
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletRequest;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.lock.ActiveLock;
private ArchivaDavResourceLocator resourceLocator;
+ private DavResourceFactory resourceFactory;
+
private File baseDir;
private final String REPOPATH = "myresource.jar";
baseDir.mkdirs();
myResource = new File(baseDir, "myresource.jar");
assertTrue("Could not create " + myResource.getAbsolutePath(), myResource.createNewFile());
+ resourceFactory = new RootContextDavResourceFactory();
resourceLocator = (ArchivaDavResourceLocator)new ArchivaDavLocatorFactory().createResourceLocator("/", REPOPATH);
resource = getDavResource(resourceLocator.getHref(false), myResource);
lockManager = new SimpleLockManager();
private DavResource getDavResource(String logicalPath, File file)
{
- return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, null);
+ return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, resourceFactory);
+ }
+
+ public void testDeleteCollection()
+ throws Exception
+ {
+ File dir = new File(baseDir, "testdir");
+ try
+ {
+ assertTrue(dir.mkdir());
+ DavResource directoryResource = getDavResource("/testdir", dir);
+ directoryResource.getCollection().removeMember(directoryResource);
+ assertFalse(dir.exists());
+ }
+ finally
+ {
+ FileUtils.deleteDirectory(dir);
+ }
+ }
+
+ public void testDeleteResource()
+ throws Exception
+ {
+ assertTrue(myResource.exists());
+ resource.getCollection().removeMember(resource);
+ assertFalse(myResource.exists());
}
public void testIsLockable()
assertEquals(0, resource.getLocks().length);
}
+
+ private class RootContextDavResourceFactory implements DavResourceFactory
+ {
+ public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
+ return new ArchivaDavResource(baseDir.getAbsolutePath(), "/", mimeTypes, session, resourceLocator, resourceFactory);
+ }
+ }
}