mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
use relative path for repository directory
This commit is contained in:
@@ -21,6 +21,9 @@ public class RepositoryPath implements ModelObject {
|
||||
@XmlTransient
|
||||
private Repository repository;
|
||||
|
||||
@XmlTransient
|
||||
private String absolutePath;
|
||||
|
||||
@XmlTransient
|
||||
private boolean toBeSynchronized;
|
||||
|
||||
@@ -30,8 +33,9 @@ public class RepositoryPath implements ModelObject {
|
||||
public RepositoryPath() {
|
||||
}
|
||||
|
||||
public RepositoryPath(String path, String id, Repository repository) {
|
||||
public RepositoryPath(String path, String absolutePath, String id, Repository repository) {
|
||||
this.path = path;
|
||||
this.absolutePath = absolutePath;
|
||||
this.id = id;
|
||||
this.repository = repository;
|
||||
}
|
||||
@@ -98,4 +102,12 @@ public class RepositoryPath implements ModelObject {
|
||||
public void setToBeSynchronized(boolean toBeSynchronized) {
|
||||
this.toBeSynchronized = toBeSynchronized;
|
||||
}
|
||||
|
||||
public String getAbsolutePath() {
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
public void setAbsolutePath(String absolutePath) {
|
||||
this.absolutePath = absolutePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.repository.xml;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.PathBasedRepositoryDAO;
|
||||
@@ -91,18 +92,17 @@ public class XmlRepositoryDAO
|
||||
|
||||
@Override
|
||||
public void modify(Repository repository) {
|
||||
String path = getPath(repository).toString();
|
||||
String path = getPath(repository).toAbsolutePath().toString();
|
||||
db.remove(repository.getId());
|
||||
RepositoryPath repositoryPath = new RepositoryPath(path, repository.getId(), repository.clone());
|
||||
RepositoryPath repositoryPath = new RepositoryPath(initialRepositoryLocationResolver.getRelativePath(path), path, repository.getId(), repository.clone());
|
||||
repositoryPath.setToBeSynchronized(true);
|
||||
add(repositoryPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Repository repository) {
|
||||
String path = getPath(repository).toString();
|
||||
|
||||
RepositoryPath repositoryPath = new RepositoryPath(path, repository.getId(), repository.clone());
|
||||
String path = getPath(repository).toAbsolutePath().toString();
|
||||
RepositoryPath repositoryPath = new RepositoryPath(initialRepositoryLocationResolver.getRelativePath(path),path, repository.getId(), repository.clone());
|
||||
repositoryPath.setToBeSynchronized(true);
|
||||
add(repositoryPath);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public class XmlRepositoryDAO
|
||||
.filter(repoPath -> repoPath.getId().equals(repository.getId()))
|
||||
.findFirst()
|
||||
.map(RepositoryPath::getPath)
|
||||
.map(relativePath -> Paths.get(new File(initialRepositoryLocationResolver.getBaseDirectory(), relativePath).toURI()))
|
||||
.map(relativePath -> new File(SCMContext.getContext().getBaseDirectory(), relativePath).toPath())
|
||||
.orElseGet(createRepositoryPath(repository));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
package sonia.scm.repository.xml;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.StoreConstants;
|
||||
import sonia.scm.store.StoreException;
|
||||
@@ -64,7 +66,7 @@ public class XmlRepositoryMapAdapter extends XmlAdapter<XmlRepositoryList, Map<S
|
||||
for (RepositoryPath repositoryPath : repositoryPaths.getRepositoryPaths()) {
|
||||
if (repositoryPath.toBeSynchronized()) {
|
||||
|
||||
File dir = new File(repositoryPath.getPath());
|
||||
File dir = new File(repositoryPath.getAbsolutePath());
|
||||
if (!dir.exists()) {
|
||||
IOUtil.mkdirs(dir);
|
||||
}
|
||||
@@ -85,13 +87,15 @@ public class XmlRepositoryMapAdapter extends XmlAdapter<XmlRepositoryList, Map<S
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, RepositoryPath> unmarshal(XmlRepositoryList repositories) {
|
||||
public Map<String, RepositoryPath> unmarshal(XmlRepositoryList repositoryPaths) {
|
||||
Map<String, RepositoryPath> repositoryPathMap = new LinkedHashMap<>();
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(Repository.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
for (RepositoryPath repositoryPath : repositories) {
|
||||
Repository repository = (Repository) unmarshaller.unmarshal(getRepositoryMetadataFile(new File(repositoryPath.getPath())));
|
||||
for (RepositoryPath repositoryPath : repositoryPaths) {
|
||||
SCMContextProvider contextProvider = SCMContext.getContext();
|
||||
File baseDirectory = contextProvider.getBaseDirectory();
|
||||
Repository repository = (Repository) unmarshaller.unmarshal(getRepositoryMetadataFile(new File(baseDirectory, repositoryPath.getPath())));
|
||||
repositoryPath.setRepository(repository);
|
||||
repositoryPathMap.put(XmlRepositoryDatabase.createKey(repository), repositoryPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user