Skip to content
Snippets Groups Projects
Verified Commit ef3c3822 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: file system: import

parent 23714b5e
Branches
No related tags found
1 merge request!77Draft: ENH: file system: import
Pipeline #31811 failed
Showing
with 88 additions and 13 deletions
...@@ -816,21 +816,31 @@ public abstract class Entity extends AbstractObservable implements EntityInterfa ...@@ -816,21 +816,31 @@ public abstract class Entity extends AbstractObservable implements EntityInterfa
linkTarget = Integer.parseInt(element.getAttributeValue("linktarget")); linkTarget = Integer.parseInt(element.getAttributeValue("linktarget"));
} }
// Parse IMPORT
boolean isImport = false;
if (element.getAttribute("import") != null
&& element.getAttributeValue("import").equals("true")) {
isImport = true;
}
// Store PATH, HASH, SIZE, TMPIDENTIFYER // Store PATH, HASH, SIZE, TMPIDENTIFYER
if (tmpIdentifier != null || checksum != null || path != null || size != null) { if (tmpIdentifier != null || checksum != null || path != null || size != null) {
// legacy clients (which use this api) always use sha512. // legacy clients (which use this api) always use sha512.
Hash hash = Hash.create(checksum, 0, Hasher.Default); Hash hash = Hash.create(checksum, 0, Hasher.Default);
FSODescriptor fso;
if (getRole() == Role.Directory) { if (getRole() == Role.Directory) {
setFSODescriptor(FSODescriptor.createDir(FileSystem.DEFAULT_BACKEND, new Path(path))); fso = FSODescriptor.createDir(FileSystem.DEFAULT_BACKEND, new Path(path));
} else if (getRole() == Role.Link) { } else if (getRole() == Role.Link) {
setFSODescriptor( fso =
FSODescriptor.createLink( FSODescriptor.createLink(
FileSystem.DEFAULT_BACKEND, new Path(path), new EntityID(linkTarget))); FileSystem.DEFAULT_BACKEND, new Path(path), new EntityID(linkTarget));
} else { } else {
setFSODescriptor( fso =
new FSODescriptor( new FSODescriptor(
FileSystem.DEFAULT_BACKEND, null, hash, new Path(path), size, tmpIdentifier)); FileSystem.DEFAULT_BACKEND, null, hash, new Path(path), size, tmpIdentifier);
} }
fso.setImport(isImport);
setFSODescriptor(fso);
} }
// Parse flags // Parse flags
......
...@@ -43,6 +43,7 @@ public class FSODescriptor implements VirtualFSODescriptorInterface { ...@@ -43,6 +43,7 @@ public class FSODescriptor implements VirtualFSODescriptorInterface {
protected List<VirtualFSODescriptorInterface> children; protected List<VirtualFSODescriptorInterface> children;
private RealFSODescriptorInterface twin; private RealFSODescriptorInterface twin;
private EntityID linkTarget = null; private EntityID linkTarget = null;
private boolean isImport = false;
public FSODescriptor( public FSODescriptor(
final String fileStorageId, final String fileStorageId,
...@@ -283,4 +284,13 @@ public class FSODescriptor implements VirtualFSODescriptorInterface { ...@@ -283,4 +284,13 @@ public class FSODescriptor implements VirtualFSODescriptorInterface {
result.type = ObjectType.LINK; result.type = ObjectType.LINK;
return result; return result;
} }
@Override
public boolean isImport() {
return isImport;
}
public void setImport(boolean isImport) {
this.isImport = isImport;
}
} }
...@@ -48,8 +48,10 @@ public interface FileStorageInterface { ...@@ -48,8 +48,10 @@ public interface FileStorageInterface {
public abstract Hash getHash(FSODescriptorInterface fso, String algorithm); public abstract Hash getHash(FSODescriptorInterface fso, String algorithm);
/** Return true iff an object with this key exists. */ /** Return true if this object exists. */
public abstract boolean exists(String key); public abstract boolean exists(VirtualFSODescriptorInterface fso);
public abstract Iterable<? extends RealFSODescriptorInterface> list(String prefix); public abstract Iterable<? extends RealFSODescriptorInterface> list(String prefix);
public abstract RealFSODescriptorInterface resolve(VirtualFSODescriptorInterface fso);
} }
...@@ -84,10 +84,10 @@ public class FileSystem implements FileSystemInterface { ...@@ -84,10 +84,10 @@ public class FileSystem implements FileSystemInterface {
// return false; // return false;
// } // }
public static Boolean exists(FSODescriptorInterface fso) { public static Boolean exists(VirtualFSODescriptorInterface fso) {
FileStorageInterface fileStorage = getInstance().getFileStorage(fso); FileStorageInterface fileStorage = getInstance().getFileStorage(fso);
if (fileStorage.getCapabilities().existence) { if (fileStorage.getCapabilities().existence) {
return fileStorage.exists(fso.getKey()); return fileStorage.exists(fso);
} }
return null; return null;
} }
...@@ -98,6 +98,11 @@ public class FileSystem implements FileSystemInterface { ...@@ -98,6 +98,11 @@ public class FileSystem implements FileSystemInterface {
return fileStorage.move(fso, target); return fileStorage.move(fso, target);
} }
public RealFSODescriptorInterface resolve(VirtualFSODescriptorInterface fso) {
FileStorageInterface fileStorage = getInstance().getFileStorage(fso);
return fileStorage.resolve(fso);
}
// public static boolean resolve(FSODescriptorInterface fso) { // public static boolean resolve(FSODescriptorInterface fso) {
// FileStorageInterface fileStorage = getInstance().getFileStorage(fso); // FileStorageInterface fileStorage = getInstance().getFileStorage(fso);
// return fileStorage.resolve(fso); // return fileStorage.resolve(fso);
......
...@@ -284,6 +284,16 @@ public abstract class LocalFileStorage implements FileStorageInterface { ...@@ -284,6 +284,16 @@ public abstract class LocalFileStorage implements FileStorageInterface {
return new LocalFSODescriptor(this, key); return new LocalFSODescriptor(this, key);
} }
@Override
public RealFSODescriptorInterface resolve(VirtualFSODescriptorInterface fso) {
String key = fso.getKey();
if (key == null) {
key = fso.getPath().toString();
fso.setKey(key);
}
return resolve(key);
}
@Override @Override
public Undoable move(final RealFSODescriptorInterface file, VirtualFSODescriptorInterface target) public Undoable move(final RealFSODescriptorInterface file, VirtualFSODescriptorInterface target)
throws Message { throws Message {
...@@ -698,7 +708,12 @@ public abstract class LocalFileStorage implements FileStorageInterface { ...@@ -698,7 +708,12 @@ public abstract class LocalFileStorage implements FileStorageInterface {
} }
@Override @Override
public boolean exists(String key) { public boolean exists(VirtualFSODescriptorInterface fso) {
String key = fso.getKey();
if (key == null) {
key = fso.getPath().toString();
fso.setKey(key);
}
return !isFree(key); return !isFree(key);
} }
......
...@@ -64,7 +64,7 @@ public class SharedFileStorage extends LocalFileStorage { ...@@ -64,7 +64,7 @@ public class SharedFileStorage extends LocalFileStorage {
} }
// known to this fs? // known to this fs?
if (!exists(path)) { if (!exists(getFile(path))) {
return null; return null;
} }
......
...@@ -126,4 +126,6 @@ public interface VirtualFSODescriptorInterface extends FSODescriptorInterface { ...@@ -126,4 +126,6 @@ public interface VirtualFSODescriptorInterface extends FSODescriptorInterface {
public abstract Path getLinkTargetPath(); public abstract Path getLinkTargetPath();
public abstract void setLinkTargetPath(Path target); public abstract void setLinkTargetPath(Path target);
public abstract boolean isImport();
} }
...@@ -244,7 +244,7 @@ class RunThroughInternalFileSystem extends ConsistencyCheckStrategy { ...@@ -244,7 +244,7 @@ class RunThroughInternalFileSystem extends ConsistencyCheckStrategy {
return null; return null;
} }
private RealFSODescriptorInterface resolve(FSODescriptorInterface fso) { private RealFSODescriptorInterface resolve(VirtualFSODescriptorInterface fso) {
RealFSODescriptorInterface result = null; RealFSODescriptorInterface result = null;
result = FileSystem.getInstance().resolve(fso.getFileStorageId(), fso.getKey()); result = FileSystem.getInstance().resolve(fso.getFileStorageId(), fso.getKey());
Boolean exists = FileSystem.exists(fso); Boolean exists = FileSystem.exists(fso);
......
...@@ -22,8 +22,11 @@ ...@@ -22,8 +22,11 @@
*/ */
package org.caosdb.server.jobs; package org.caosdb.server.jobs;
import org.caosdb.server.entity.Message;
import org.caosdb.server.filesystem.FileSystem;
import org.caosdb.server.filesystem.RealFSODescriptorInterface; import org.caosdb.server.filesystem.RealFSODescriptorInterface;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface; import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.utils.ServerMessages;
public abstract class FilesJob extends EntityJob { public abstract class FilesJob extends EntityJob {
...@@ -32,11 +35,23 @@ public abstract class FilesJob extends EntityJob { ...@@ -32,11 +35,23 @@ public abstract class FilesJob extends EntityJob {
* *
* @param tmpFileId * @param tmpFileId
* @return * @return
* @throws Message
*/ */
protected RealFSODescriptorInterface getRealFSODescriptor(VirtualFSODescriptorInterface fso) { protected RealFSODescriptorInterface getRealFSODescriptor(VirtualFSODescriptorInterface fso)
throws Message {
if (fso.getTwin() != null) { if (fso.getTwin() != null) {
return fso.getTwin(); return fso.getTwin();
} }
if (fso.isImport()) {
if (FileSystem.exists(getEntity().getFSODescriptor())) {
RealFSODescriptorInterface twin =
FileSystem.getInstance().resolve(getEntity().getFSODescriptor());
getEntity().getFSODescriptor().setTwin(twin);
return twin;
} else if (getEntity().getFSODescriptor().isImport()) {
throw ServerMessages.FILE_IMPORT_FAILED_FILE_DOES_NOT_EXIST;
}
}
return getContainer().getFiles().get(fso.getTmpIdentifier()); return getContainer().getFiles().get(fso.getTmpIdentifier());
} }
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package org.caosdb.server.jobs.core; package org.caosdb.server.jobs.core;
import org.caosdb.server.database.backend.transaction.CheckTargetPath; import org.caosdb.server.database.backend.transaction.CheckTargetPath;
import org.caosdb.server.filesystem.FileSystem;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface; import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.jobs.FilesJob; import org.caosdb.server.jobs.FilesJob;
import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.EntityStatus;
...@@ -51,6 +52,15 @@ public class CheckTargetPathValid extends FilesJob { ...@@ -51,6 +52,15 @@ public class CheckTargetPathValid extends FilesJob {
// check that target path is not owned by another entity. // check that target path is not owned by another entity.
final CheckTargetPath t = new CheckTargetPath(getEntity(), getContainer()); final CheckTargetPath t = new CheckTargetPath(getEntity(), getContainer());
execute(t); execute(t);
// check if the fso exists in the file storage
if (FileSystem.exists(getEntity().getFSODescriptor())) {
if (getEntity().getFSODescriptor().isImport()) {
// ok?
} else {
// is update?
}
}
} }
} }
} }
...@@ -168,6 +168,12 @@ public class ServerMessages { ...@@ -168,6 +168,12 @@ public class ServerMessages {
MessageCode.MESSAGE_CODE_FILE_HAS_NOT_BEEN_UPLOAED, MessageCode.MESSAGE_CODE_FILE_HAS_NOT_BEEN_UPLOAED,
"File has not been uploaded."); "File has not been uploaded.");
public static final Message FILE_IMPORT_FAILED_FILE_DOES_NOT_EXIST =
new Message(
MessageType.Error,
MessageCode.MESSAGE_CODE_UNKNOWN,
"This file does not exist. It cannot be imported.");
public static final Message CANNOT_MOVE_FILE_TO_TARGET_PATH = public static final Message CANNOT_MOVE_FILE_TO_TARGET_PATH =
new Message( new Message(
MessageType.Error, MessageType.Error,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment