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

WIP: file storage refactoring: directory

parent 40936177
Branches
No related tags found
1 merge request!74Draft: ENH: file system: directory
Pipeline #31744 failed
......@@ -4,6 +4,7 @@ import org.caosdb.server.database.BackendTransaction;
import org.caosdb.server.database.exceptions.EntityDoesNotExistException;
import org.caosdb.server.entity.EntityInterface;
import org.caosdb.server.entity.Message;
import org.caosdb.server.entity.container.TransactionContainer;
import org.caosdb.server.filesystem.Path;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.utils.ServerMessages;
......@@ -19,33 +20,58 @@ import org.caosdb.server.utils.ServerMessages;
public class CheckTargetPath extends BackendTransaction {
private final EntityInterface entity;
private TransactionContainer container;
public CheckTargetPath(final EntityInterface entity) {
public CheckTargetPath(final EntityInterface entity, TransactionContainer container) {
this.container = container;
this.entity = entity;
}
@Override
protected void execute() {
try {
checkTarget(entity);
checkTarget(entity, container);
} catch (final Message e) {
entity.addError(e);
}
}
public void checkTarget(final EntityInterface entity) throws Message {
// TODO move to transaction
final VirtualFSODescriptorInterface fd = entity.getFSODescriptor();
final Path targetPath = fd.getPath();
public void checkTarget(final EntityInterface entity, TransactionContainer container)
throws Message {
// TODO move to FileSystem or Path
for (final String segment : targetPath.getSegments()) {
if (segment.matches("^\\.{1,3}$")) {
throw ServerMessages.TARGET_PATH_NOT_ALLOWED;
checkNastyPath(entity.getFSODescriptor().getPath());
checkOwner(entity);
checkParentExists(entity, container);
}
private void checkParentExists(EntityInterface entity, TransactionContainer container)
throws Message {
Path path = entity.getFSODescriptor().getPath().getParent();
if (path == null) {
// root is parent
return;
}
for (EntityInterface e : container) {
if (e.getFSODescriptor() != null && e.getFSODescriptor().getPath() != null) {
if (e.getFSODescriptor().getPath().equals(path)) {
// found the parent in the current container
return;
}
}
}
GetFileEntityByPath t = new GetFileEntityByPath(path, false);
try {
execute(t);
} catch (final EntityDoesNotExistException e) {
throw ServerMessages.TARGET_PARENT_DIRECTORY_DOES_NOT_EXIST;
}
}
final GetFileEntityByPath t = new GetFileEntityByPath(targetPath, true);
private void checkOwner(EntityInterface entity) throws Message {
final VirtualFSODescriptorInterface fd = entity.getFSODescriptor();
final Path path = fd.getPath();
final GetFileEntityByPath t = new GetFileEntityByPath(path, false);
try {
execute(t);
} catch (final EntityDoesNotExistException e) {
......@@ -60,4 +86,12 @@ public class CheckTargetPath extends BackendTransaction {
throw ServerMessages.TARGET_PATH_EXISTS;
}
}
private void checkNastyPath(Path path) throws Message {
for (final String segment : path.getSegments()) {
if (segment.matches("^\\.{1,3}$")) {
throw ServerMessages.TARGET_PATH_NOT_ALLOWED;
}
}
}
}
......@@ -38,7 +38,15 @@ public abstract class EntityFlagJob extends EntityJob {
@Override
protected void run() {
if (this.value == null) {
this.value = this.getClass().getAnnotation(JobAnnotation.class).defaultValue();
JobAnnotation annotation = getClass().getAnnotation(JobAnnotation.class);
if (getContainer().getFlags() != null) {
this.value =
this.getContainer()
.getFlags()
.getOrDefault(annotation.flag(), annotation.defaultValue());
} else {
this.value = annotation.defaultValue();
}
}
job(this.value);
}
......
......@@ -12,9 +12,14 @@ import org.caosdb.server.filesystem.Path;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.jobs.EntityFlagJob;
import org.caosdb.server.jobs.JobAnnotation;
import org.caosdb.server.jobs.TransactionStage;
import org.caosdb.server.permissions.EntityACL;
@JobAnnotation(flag = "autoCreateDirs", defaultValue = "true", loadAlways = true)
@JobAnnotation(
flag = "autoCreateDirs",
defaultValue = "true",
loadAlways = true,
stage = TransactionStage.PRE_CHECK)
public class AutoCreateDirs extends EntityFlagJob {
@Override
......
......@@ -48,7 +48,8 @@ public class CheckTargetPathValid extends FilesJob {
return;
}
final CheckTargetPath t = new CheckTargetPath(getEntity());
// check that target path is not owned by another entity.
final CheckTargetPath t = new CheckTargetPath(getEntity(), getContainer());
execute(t);
}
}
......
......@@ -126,6 +126,12 @@ public class ServerMessages {
MessageCode.MESSAGE_CODE_TARGET_PATH_EXISTS,
"This target path does already exist.");
public static final Message TARGET_PARENT_DIRECTORY_DOES_NOT_EXIST =
new Message(
MessageType.Error,
MessageCode.MESSAGE_CODE_UNKNOWN,
"The parent directory of the target path does not exist.");
public static final Message PROPERTY_HAS_NO_UNIT =
new Message(
MessageType.Error,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment