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

Merge branch 'f-filesystem-directory' into f-filesystem-link

parents 3278fe69 605faa81
No related branches found
No related tags found
1 merge request!76Draft: ENH: file system: link
...@@ -4,6 +4,7 @@ import org.caosdb.server.database.BackendTransaction; ...@@ -4,6 +4,7 @@ import org.caosdb.server.database.BackendTransaction;
import org.caosdb.server.database.exceptions.EntityDoesNotExistException; import org.caosdb.server.database.exceptions.EntityDoesNotExistException;
import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.EntityInterface;
import org.caosdb.server.entity.Message; import org.caosdb.server.entity.Message;
import org.caosdb.server.entity.container.TransactionContainer;
import org.caosdb.server.filesystem.Path; import org.caosdb.server.filesystem.Path;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface; import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.utils.ServerMessages; import org.caosdb.server.utils.ServerMessages;
...@@ -19,33 +20,58 @@ import org.caosdb.server.utils.ServerMessages; ...@@ -19,33 +20,58 @@ import org.caosdb.server.utils.ServerMessages;
public class CheckTargetPath extends BackendTransaction { public class CheckTargetPath extends BackendTransaction {
private final EntityInterface entity; 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; this.entity = entity;
} }
@Override @Override
protected void execute() { protected void execute() {
try { try {
checkTarget(entity); checkTarget(entity, container);
} catch (final Message e) { } catch (final Message e) {
entity.addError(e); entity.addError(e);
} }
} }
public void checkTarget(final EntityInterface entity) throws Message { public void checkTarget(final EntityInterface entity, TransactionContainer container)
// TODO move to transaction throws Message {
final VirtualFSODescriptorInterface fd = entity.getFSODescriptor();
final Path targetPath = fd.getPath();
// TODO move to FileSystem or Path checkNastyPath(entity.getFSODescriptor().getPath());
for (final String segment : targetPath.getSegments()) { checkOwner(entity);
if (segment.matches("^\\.{1,3}$")) { checkParentExists(entity, container);
throw ServerMessages.TARGET_PATH_NOT_ALLOWED; }
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 { try {
execute(t); execute(t);
} catch (final EntityDoesNotExistException e) { } catch (final EntityDoesNotExistException e) {
...@@ -60,4 +86,12 @@ public class CheckTargetPath extends BackendTransaction { ...@@ -60,4 +86,12 @@ public class CheckTargetPath extends BackendTransaction {
throw ServerMessages.TARGET_PATH_EXISTS; 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 { ...@@ -38,7 +38,15 @@ public abstract class EntityFlagJob extends EntityJob {
@Override @Override
protected void run() { protected void run() {
if (this.value == null) { 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); job(this.value);
} }
......
...@@ -12,9 +12,14 @@ import org.caosdb.server.filesystem.Path; ...@@ -12,9 +12,14 @@ import org.caosdb.server.filesystem.Path;
import org.caosdb.server.filesystem.VirtualFSODescriptorInterface; import org.caosdb.server.filesystem.VirtualFSODescriptorInterface;
import org.caosdb.server.jobs.EntityFlagJob; import org.caosdb.server.jobs.EntityFlagJob;
import org.caosdb.server.jobs.JobAnnotation; import org.caosdb.server.jobs.JobAnnotation;
import org.caosdb.server.jobs.TransactionStage;
import org.caosdb.server.permissions.EntityACL; 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 { public class AutoCreateDirs extends EntityFlagJob {
@Override @Override
......
...@@ -48,7 +48,8 @@ public class CheckTargetPathValid extends FilesJob { ...@@ -48,7 +48,8 @@ public class CheckTargetPathValid extends FilesJob {
return; 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); execute(t);
} }
} }
......
...@@ -126,6 +126,12 @@ public class ServerMessages { ...@@ -126,6 +126,12 @@ public class ServerMessages {
MessageCode.MESSAGE_CODE_TARGET_PATH_EXISTS, MessageCode.MESSAGE_CODE_TARGET_PATH_EXISTS,
"This target path does already exist."); "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 = public static final Message PROPERTY_HAS_NO_UNIT =
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