Skip to content
Snippets Groups Projects
Commit 17f8b084 authored by srosse's avatar srosse
Browse files

OO-1444: use only the lock system built in OpenOLAT

parent 14a785b1
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,6 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -53,7 +53,6 @@ public class VFSLockManagerImpl implements VFSLockManager {
* Key : path <br> * Key : path <br>
* Value : LockInfo * Value : LockInfo
*/ */
private Map<String,LockInfo> resourceLocks = new ConcurrentHashMap<String,LockInfo>();
private Map<File,LockInfo> fileLocks = new ConcurrentHashMap<File,LockInfo>(); private Map<File,LockInfo> fileLocks = new ConcurrentHashMap<File,LockInfo>();
/** /**
...@@ -89,7 +88,7 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -89,7 +88,7 @@ public class VFSLockManagerImpl implements VFSLockManager {
if(file != null && fileLocks.containsKey(file)) { if(file != null && fileLocks.containsKey(file)) {
LockInfo lock = fileLocks.get(file); LockInfo lock = fileLocks.get(file);
if (lock != null && lock.hasExpired()) { if (lock != null && lock.hasExpired()) {
resourceLocks.remove(lock.getWebPath()); //LOCK resourceLocks.remove(lock.getWebPath());
fileLocks.remove(file); fileLocks.remove(file);
} else { } else {
return true; return true;
...@@ -109,7 +108,7 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -109,7 +108,7 @@ public class VFSLockManagerImpl implements VFSLockManager {
if(file != null && fileLocks.containsKey(file)) { if(file != null && fileLocks.containsKey(file)) {
LockInfo lock = fileLocks.get(file); LockInfo lock = fileLocks.get(file);
if (lock != null && lock.hasExpired()) { if (lock != null && lock.hasExpired()) {
resourceLocks.remove(lock.getWebPath()); //LOCK resourceLocks.remove(lock.getWebPath());
fileLocks.remove(file); fileLocks.remove(file);
} else { } else {
Long lockedBy = lock.getLockedBy(); Long lockedBy = lock.getLockedBy();
...@@ -189,7 +188,7 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -189,7 +188,7 @@ public class VFSLockManagerImpl implements VFSLockManager {
lock.setVfsLock(false); lock.setVfsLock(false);
} else { } else {
if(lock.getWebPath() != null) { if(lock.getWebPath() != null) {
resourceLocks.remove(lock.getWebPath()); //LOCK resourceLocks.remove(lock.getWebPath());
} }
fileLocks.remove(file); fileLocks.remove(file);
unlocked = true; unlocked = true;
...@@ -203,13 +202,13 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -203,13 +202,13 @@ public class VFSLockManagerImpl implements VFSLockManager {
} }
public Iterator<LockInfo> getResourceLocks() { public Iterator<LockInfo> getResourceLocks() {
return resourceLocks.values().iterator(); return fileLocks.values().iterator();
} }
public LockInfo getResourceLock(WebResource resource) { public LockInfo getResourceLock(WebResource resource) {
if(resourceLocks.containsKey(resource.getPath())) { /* LOCK if(resourceLocks.containsKey(resource.getPath())) {
return resourceLocks.get(resource.getPath()); return resourceLocks.get(resource.getPath());
} }*/
File file = extractFile(resource); File file = extractFile(resource);
if(file != null && fileLocks.containsKey(file)) { if(file != null && fileLocks.containsKey(file)) {
...@@ -285,7 +284,7 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -285,7 +284,7 @@ public class VFSLockManagerImpl implements VFSLockManager {
} }
public void putResourceLock(WebResource resource, LockInfo lock) { public void putResourceLock(WebResource resource, LockInfo lock) {
resourceLocks.put(resource.getPath(), lock); //LOCK resourceLocks.put(resource.getPath(), lock);
File file = extractFile(resource); File file = extractFile(resource);
if(file != null) { if(file != null) {
fileLocks.put(file, lock); fileLocks.put(file, lock);
...@@ -317,18 +316,18 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -317,18 +316,18 @@ public class VFSLockManagerImpl implements VFSLockManager {
} }
public void removeResourceLock(WebResource resource) { public void removeResourceLock(WebResource resource) {
LockInfo lock = resourceLocks.get(resource.getPath()); //LOCK
if(lock != null) { File file = extractFile(resource);
if(lock.isVfsLock()) { if(file != null) {
lock.setWebDAVLock(false); LockInfo lock = fileLocks.get(file);
} else { if(lock != null) {
resourceLocks.remove(resource.getPath()); if(lock.isVfsLock()) {
File file = extractFile(resource); lock.setWebDAVLock(false);
if(file != null) { } else {
fileLocks.remove(file); fileLocks.remove(file);
} }
} }
} }
} }
public Vector<String> getLockNullResource(WebResource resource) { public Vector<String> getLockNullResource(WebResource resource) {
...@@ -376,11 +375,15 @@ public class VFSLockManagerImpl implements VFSLockManager { ...@@ -376,11 +375,15 @@ public class VFSLockManagerImpl implements VFSLockManager {
return true; return true;
} }
} }
LockInfo lock = resourceLocks.get(path); File file = extractFile(resource);
if(file == null) {
return false;//lock only file
}
LockInfo lock = fileLocks.get(file);
if (lock != null && lock.hasExpired()) { if (lock != null && lock.hasExpired()) {
resourceLocks.remove(path); fileLocks.remove(file);
} else if (lock != null) { } else if (lock != null) {
// At least one of the tokens of the locks must have been given // At least one of the tokens of the locks must have been given
Iterator<String> tokenList = lock.tokens(); Iterator<String> tokenList = lock.tokens();
......
...@@ -51,6 +51,8 @@ import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl; ...@@ -51,6 +51,8 @@ import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.Roles; import org.olat.core.id.Roles;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSItem;
...@@ -75,6 +77,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -75,6 +77,8 @@ import org.springframework.beans.factory.annotation.Autowired;
*/ */
public class WebDAVCommandsTest extends WebDAVTestCase { public class WebDAVCommandsTest extends WebDAVTestCase {
private static final OLog log = Tracing.createLoggerFor(WebDAVCommandsTest.class);
@Autowired @Autowired
private DB dbInstance; private DB dbInstance;
@Autowired @Autowired
...@@ -520,7 +524,7 @@ public class WebDAVCommandsTest extends WebDAVTestCase { ...@@ -520,7 +524,7 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
//author check file //author check file
URI textUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test.txt").build(); URI textUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test.txt").build();
String textPropfind = conn.propfind(textUri, 0); String textPropfind = conn.propfind(textUri, 0);
System.out.println(textPropfind); log.info(textPropfind);
//author lock the file //author lock the file
String lockToken = conn.lock(textUri, UUID.randomUUID().toString()); String lockToken = conn.lock(textUri, UUID.randomUUID().toString());
...@@ -559,6 +563,52 @@ public class WebDAVCommandsTest extends WebDAVTestCase { ...@@ -559,6 +563,52 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
IOUtils.closeQuietly(conn); IOUtils.closeQuietly(conn);
} }
@Test
public void testLock_public_samePathLock()
throws IOException, URISyntaxException {
//create a user
Identity user1 = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2d");
Identity user2 = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2e");
//create a file
String publicPath1 = FolderConfig.getUserHomes() + "/" + user1.getName() + "/public";
VFSContainer vfsPublic1 = new OlatRootFolderImpl(publicPath1, null);
VFSItem item1 = createFile(vfsPublic1, "test.txt");
Assert.assertNotNull(item1);
String publicPath2 = FolderConfig.getUserHomes() + "/" + user2.getName() + "/public";
VFSContainer vfsPublic2 = new OlatRootFolderImpl(publicPath2, null);
VFSItem item2 = createFile(vfsPublic2, "test.txt");
Assert.assertNotNull(item2);
//lock the item with WebDAV
WebDAVConnection conn1 = new WebDAVConnection();
conn1.setCredentials(user1.getName(), "A6B7C8");
//user 1 lock the file
URI textUri = conn1.getBaseURI().path("webdav").path("home").path("public").path("test.txt").build();
String textPropfind1 = conn1.propfind(textUri, 0);
Assert.assertNotNull(textPropfind1);
// lock the path /webdav/home/public/test.txt
String lockToken1 = conn1.lock(textUri, UUID.randomUUID().toString());
Assert.assertNotNull(lockToken1);
//user 2 lock its own file
WebDAVConnection conn2 = new WebDAVConnection();
conn2.setCredentials(user2.getName(), "A6B7C8");
String textPropfind2 = conn2.propfind(textUri, 0);
Assert.assertNotNull(textPropfind2);
// lock the path /webdav/home/public/test.txt
String lockToken2 = conn2.lock(textUri, UUID.randomUUID().toString());
Assert.assertNotNull(lockToken2);
//closes
conn1.close();
conn2.close();
}
@Test @Test
public void testDelete() public void testDelete()
throws IOException, URISyntaxException { throws IOException, URISyntaxException {
...@@ -679,7 +729,8 @@ public class WebDAVCommandsTest extends WebDAVTestCase { ...@@ -679,7 +729,8 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
Assert.assertTrue(customizingXml.contains("<D:href>/webdav/customizing/</D:href>")); Assert.assertTrue(customizingXml.contains("<D:href>/webdav/customizing/</D:href>"));
//PUT in the folder //PUT in the folder
URI textUri = conn.getBaseURI().path("webdav").path("customizing").path("infos.txt").build(); String randomFilename = "infos" + UUID.randomUUID() + ".txt";
URI textUri = conn.getBaseURI().path("webdav").path("customizing").path(randomFilename).build();
HttpPut put = conn.createPut(textUri); HttpPut put = conn.createPut(textUri);
InputStream dataStream = WebDAVCommandsTest.class.getResourceAsStream("text.txt"); InputStream dataStream = WebDAVCommandsTest.class.getResourceAsStream("text.txt");
InputStreamEntity entity = new InputStreamEntity(dataStream, -1); InputStreamEntity entity = new InputStreamEntity(dataStream, -1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment