Skip to content

Commit

Permalink
Fix get-locks cmd not properly filtering paths when using HTTP LFS …
Browse files Browse the repository at this point in the history
…server (git-as-svn#336)
  • Loading branch information
slonopotamus committed Mar 16, 2020
1 parent 99b4a54 commit 0a9431e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/docs/asciidoc/_changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif::[]
== Unreleased

* Upgrade httpclient to 4.5.12. https://github.com/bozaro/git-as-svn/issues/335[#335]
* Fix `get-locks` cmd not properly filtering paths when using HTTP LFS server

== 1.24.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ru.bozaro.gitlfs.common.VerifyLocksResult;
import ru.bozaro.gitlfs.common.data.*;
import svnserver.Loggers;
import svnserver.StringHelper;
import svnserver.auth.User;
import svnserver.ext.gitlfs.storage.LfsReader;
import svnserver.ext.gitlfs.storage.LfsStorage;
Expand All @@ -36,7 +37,6 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import static svnserver.repository.locks.LockDesc.toLfsPath;

Expand Down Expand Up @@ -118,9 +118,19 @@ public LockDesc unlock(@NotNull User user, @Nullable GitBranch branch, boolean b
@NotNull
@Override
public final LockDesc[] getLocks(@NotNull User user, @Nullable GitBranch branch, @Nullable String path, @Nullable String lockId) throws IOException {
path = StringHelper.normalize(path == null ? "/" : path);

final Ref ref = branch == null ? null : new Ref(branch.getShortBranchName());
final List<Lock> locks = lfsClient(user).listLocks(toLfsPath(path), lockId, ref);
final List<LockDesc> result = locks.stream().map(LockDesc::toLockDesc).collect(Collectors.toList());
final List<Lock> locks = lfsClient(user).listLocks(null, lockId, ref);

final List<LockDesc> result = new ArrayList<>();
for (Lock lock : locks) {
final LockDesc lockDesc = LockDesc.toLockDesc(lock);
if (!StringHelper.isParentPath(path, lockDesc.getPath()))
continue;

result.add(lockDesc);
}
return result.toArray(LockDesc.emptyArray);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.concurrent.ConcurrentSkipListMap;

import static svnserver.server.SvnFilePropertyTest.propsBinary;
import static svnserver.server.SvnFilePropertyTest.propsEolNative;

/**
* Simple test for LfsLocalStorage.
Expand Down Expand Up @@ -150,7 +149,7 @@ public static void checkLfs(@NotNull LfsStorage storage, @NotNull User user) thr
public static void checkLocks(@NotNull LfsStorage storage, @NotNull User user) throws LockConflictException, IOException, SVNException {
final LockDesc[] locks1;
try {
locks1 = storage.lock(user, null, null, false, new LockTarget[]{new LockTarget("/1.txt", 1)});
locks1 = storage.lock(user, null, null, false, new LockTarget[]{new LockTarget("/dir/1.txt", 1)});
} catch (RequestException e) {
if (e.getStatusCode() == HttpServletResponse.SC_NOT_FOUND)
// LFS locks are not supported
Expand All @@ -160,12 +159,12 @@ public static void checkLocks(@NotNull LfsStorage storage, @NotNull User user) t
}

Assert.assertEquals(locks1.length, 1);
Assert.assertEquals(locks1[0].getPath(), "/1.txt");
Assert.assertEquals(locks1[0].getPath(), "/dir/1.txt");

final LockDesc[] locks2 = storage.getLocks(user, null, "/1.txt", (String) null);
final LockDesc[] locks2 = storage.getLocks(user, null, "/dir/", (String) null);
Assert.assertEquals(locks2, locks1);

final LockDesc[] locks3 = storage.unlock(user, null, false, new UnlockTarget[]{new UnlockTarget("/1.txt", locks1[0].getToken())});
final LockDesc[] locks3 = storage.unlock(user, null, false, new UnlockTarget[]{new UnlockTarget("/dir/1.txt", locks1[0].getToken())});
Assert.assertEquals(locks3, locks1);

storage.lock(User.getAnonymous(), null, "2.txt");
Expand Down

0 comments on commit 0a9431e

Please sign in to comment.