use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.
the class FilingImpl method copy.
/*
* Copy: PROCEDURE [ file, destinationDirectory: Handle ,
* attributes: AttributeSequence, controls: ControlSequence,
* session: Session ]
* RETURNS [ newFile: Handle ]
* REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
* AuthenticationError, ControlTypeError, ControlValueError,
* HandleError, InsertionError, SessionError, SpaceError,
* UndefinedError ]
* = 10;
*/
private static void copy(CopyParams params, CopyResults results) {
logParams("copy", params);
// check session
Session session = resolveSession(params.session);
Volume vol = session.getService().getVolume();
// check specified file handle
Handle fileHandle = Handle.get(params.handle);
if (fileHandle.isVolumeRoot()) {
// the file system root cannot be copied
new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
}
if (fileHandle.isNullHandle()) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
FileEntry fe = fileHandle.getFe();
if (fe.getParentID() == FsConstants.rootFileID) {
// file system root folders cannot be copied
new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
}
// check the destination
Handle destinationDirHandle = Handle.get(params.destinationDirectory);
if (destinationDirHandle.isVolumeRoot()) {
// the file system root cannot be target
new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
}
if (destinationDirHandle.isNullHandle()) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
FileEntry destinationDirectory = destinationDirHandle.getFe();
// copy the file and return new file
List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
try (Volume.Session modSession = vol.startModificationSession()) {
// do the copy
FileEntry newFe = modSession.copy(fe, destinationDirectory, attrSetters, session.getUsername());
// prepare results
Handle newFeHandle = new Handle(session, newFe);
newFeHandle.setIdTo(results.newHandle);
logResult("copy", results);
} catch (InterruptedException e) {
new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
} catch (Exception e) {
new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
}
// prolongate the sessions life if this took longer
session.continueUse();
}
use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.
the class FilingImpl method changeAttributes.
/*
* ChangeAttributes: PROCEDURE [ file: Handle, attributes: AttributeSequence,
* session: Session ]
* REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
* AuthenticationError, HandleError, InsertionError,
* SessionError, SpaceError, UndefinedError ]
* = 9;
*/
private static void changeAttributes(ChangeAttributesParams params, RECORD results) {
logParams("changeAttributes", params);
// check session
Session session = resolveSession(params.session);
Volume vol = session.getService().getVolume();
// check specified file handle
Handle fileHandle = Handle.get(params.handle);
if (fileHandle == null || fileHandle.isNullHandle()) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
if (fileHandle.isVolumeRoot()) {
// the file system root cannot be modified
new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
}
FileEntry fe = fileHandle.getFe();
if (fe == null) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
// change attributes
List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
try (Volume.Session modSession = vol.startModificationSession()) {
modSession.updateFileAttributes(fe, attrSetters, session.getUsername());
} catch (InterruptedException e) {
new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
} catch (EndOfMessageException e) {
new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
} catch (CourierException ce) {
// this is a RuntimeException, why is it catch-ed by Exception ???????
throw ce;
} catch (Exception e1) {
new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
}
}
use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.
the class FilingImpl method retrieve.
/*
* Retrieve: PROCEDURE [ file: Handle, content: BulkData.Sink, session: Session ]
* REPORTS [ AccessError, AuthenticationError, ConnectionError,
* HandleError, SessionError, TransferError, UndefinedError ]
* = 13;
*/
private static void retrieve(RetrieveParams params, RECORD results) {
logParams("retrieve", params);
// check session
Session session = resolveSession(params.session);
Volume vol = session.getService().getVolume();
// check specified file handle
Handle fileHandle = Handle.get(params.file);
if (fileHandle == null || fileHandle.isNullHandle()) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
FileEntry fe = fileHandle.getFe();
if (fe == null) {
new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
}
// transfer file content
try {
ByteContentSink sink = new ByteContentSink(params.content);
vol.retrieveContent(fe.getFileID(), sink, session.getUsername());
} catch (NoMoreWriteSpaceException | IOException e) {
log("## Filing.Retrieve() => %s : %s\n", e.getClass().getName(), e.getMessage());
new TransferErrorRecord(TransferProblem.aborted).raise();
}
// prolongate the sessions life if this took longer
session.continueUse();
}
use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.
the class FilingImpl method createFile.
private static FileEntry createFile(Volume.Session modificationSession, Session session, long directoryFileID, AttributeSequence pAttributes, iContentSource source, ExceptionHandler exceptionHandler) {
// get the volume
Volume vol = session.getService().getVolume();
// extract the minimal attributes => required: name ; optional: isDirectory(false), version(1/next), type(unknown)
String name = null;
boolean isDirectory = false;
Integer version = null;
Long type = null;
for (int i = 0; i < pAttributes.value.size(); i++) {
Attribute attr = pAttributes.value.get(i);
switch((int) (attr.type.get() & 0xFFFF)) {
case FilingCommon.atName:
name = attr.getAsString();
break;
case FilingCommon.atIsDirectory:
isDirectory = attr.getAsBoolean();
break;
case FilingCommon.atVersion:
version = attr.getAsCardinal();
break;
case FilingCommon.atType:
type = attr.getAsLongCardinal();
break;
}
}
if (name == null) {
new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atName).raise();
}
// create the new file
List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(pAttributes);
System.out.printf("volStartModificationsession()\n");
try {
System.out.printf("createFile( dirId = %d , isdirectory = %s , name = '%s' )\n", directoryFileID, "" + isDirectory, name);
Volume.Session modSession = (modificationSession == null) ? vol.startModificationSession() : modificationSession;
final FileEntry fe;
try {
fe = modSession.createFile(directoryFileID, isDirectory, name, version, type, session.getUsername(), attrSetters, source);
} finally {
if (modificationSession == null) {
modSession.close();
}
}
System.out.printf("-> done createFile(): fileID = %d\n", (fe != null) ? fe.getFileID() : -2);
return fe;
} catch (InterruptedException e) {
System.out.printf("!!! InterruptedException !!!\n");
new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
} catch (EndOfMessageException e) {
System.out.printf("!!! EndOfMessageException !!!\n");
new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
} catch (CourierException ce) {
// this is a RuntimeException, why is it catch-ed by Exception ???????
System.out.printf("!!! CourierException !!!\n");
throw ce;
} catch (Exception e) {
System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
if (exceptionHandler != null) {
exceptionHandler.accept(e);
} else {
new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
}
}
// keep the compiler happy
return null;
}
use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.
the class VolumeTests method main.
public static void main(String[] args) throws InterruptedException, Exception {
String volumeDirectory = prepareVolumeDir();
log("## Opening volume %s (located in: %s)\n", volumename, volumeDirectory);
Volume vol = Volume.openVolume(volumeDirectory, new TestErrorRaiser());
vol.dumpHierarchy(System.out);
log("## done opening volume\n");
sep();
log("## listing from root\n");
dumpFileList(vol.listDirectory(0, fe -> true, -1, "peter:dev:hawala"));
sep();
long folderHansFileID;
log("## get fileID of folder 'hans'\n");
{
FileEntry fe = vol.openByName("HANS", 0L, null, null, "paule:dev:hawala");
folderHansFileID = fe.getFileID();
}
sep();
log("## changing folder 'hans' to children uniqely named = false\n");
try (Session session = vol.startModificationSession()) {
FileEntry fe = vol.openByFileID(folderHansFileID, null, null, "mary:dev:hawala");
List<iValueSetter> valueSetters = new ArrayList<>();
valueSetters.add(f -> f.setChildrenUniquelyNamed(false));
session.updateFileAttributes(fe, valueSetters, "mary:dev:hawala");
}
sep();
log("## listing from root\n");
dumpFileList(vol.listDirectory(0, fe -> true, -1, null));
sep();
log("## creating first file in folder 'hans'\n");
try (Session session = vol.startModificationSession()) {
long fileId = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", null, 2L, "mats:dev:hawala");
log(" -> 'Filing4.cr.txt' -> 'Filing4.courier' => fileID = %d\n", fileId);
}
sep();
// log("## volume.dumpHierarchy()\n");
// vol.dumpHierarchy(System.out);
// sep();
log("## listing from root\n");
dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
sep();
log("########## closing and re-opening volume ######## \n");
vol.close();
vol = Volume.openVolume(volumeDirectory, new TestErrorRaiser());
sep();
// log("## volume.dumpHierarchy()\n");
// vol.dumpHierarchy(System.out);
// sep();
log("## listing from root\n");
dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
sep();
log("## creating same file in additional versions in folder 'hans'\n");
try (Session session = vol.startModificationSession()) {
long fileIdA = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", 5, 2L, "carl:dev:hawala");
log(" -> 'Filing4.cr.txt' -> 'Filing4.courier;?5?' => fileID = %d\n", fileIdA);
long fileIdB = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", null, 2L, "carl:dev:hawala");
log(" -> 'Filing4.cr.txt' -> 'Filing4.courier;?6?' => fileID = %d\n", fileIdB);
}
sep();
log("## listing from root\n");
dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
sep();
log("## trying to open the volume while still open\n");
try {
Volume.openVolume(volumeDirectory, new TestErrorRaiser());
log("ERROR ERROR ERROR :: did not get expected VolumeLockedException\n");
} catch (VolumeLockedException vle) {
log(" (OK) -> got expected VolumeLockedException\n");
}
}
Aggregations