use of org.dcache.vehicles.PnfsCreateSymLinkMessage in project dcache by dCache.
the class PnfsManagerV3 method createEntry.
public void createEntry(PnfsCreateEntryMessage pnfsMessage) {
checkArgument(pnfsMessage.getFileAttributes().isDefined(TYPE));
FileAttributes assign = pnfsMessage.getFileAttributes();
FileType type = assign.removeFileType();
Subject subject = pnfsMessage.getSubject();
String path = pnfsMessage.getPnfsPath();
try {
File file = new File(path);
checkMask(subject, file.getParent(), pnfsMessage.getAccessMask());
Set<FileAttribute> requested = pnfsMessage.getAcquire();
FileAttributes attrs = null;
switch(type) {
case DIR:
LOGGER.info("create directory {}", path);
checkMkdirAllowed(pnfsMessage);
PnfsId pnfsId = _nameSpaceProvider.createDirectory(subject, path, assign);
pnfsMessage.setPnfsId(pnfsId);
// the createEntry seem to be ok.
try {
LOGGER.info("Trying to get storageInfo for {}", pnfsId);
/* If we were allowed to create the entry above, then
* we also ought to be allowed to read it here. Hence
* we use ROOT as the subject.
*/
attrs = _nameSpaceProvider.getFileAttributes(ROOT, pnfsId, requested);
} catch (CacheException e) {
LOGGER.warn("Can't determine storageInfo: {}", e.toString());
}
break;
case REGULAR:
LOGGER.info("create file {}", path);
checkRestriction(pnfsMessage, UPLOAD);
requested.add(FileAttribute.STORAGEINFO);
requested.add(FileAttribute.PNFSID);
attrs = _nameSpaceProvider.createFile(subject, path, assign, requested);
StorageInfo info = attrs.getStorageInfo();
if (info.getKey("path") == null) {
info.setKey("path", path);
}
info.setKey("uid", Integer.toString(assign.getOwnerIfPresent().orElse(-1)));
info.setKey("gid", Integer.toString(assign.getGroupIfPresent().orElse(-1)));
// REVISIT: consider removing xattr injection once pools can accept FileAttribute.XATTR
if (assign.isDefined(XATTR)) {
assign.getXattrs().forEach((k, v) -> info.setKey(STORAGE_INFO_XATTR_PREFIX + k, v));
}
pnfsMessage.setPnfsId(attrs.getPnfsId());
break;
case LINK:
checkArgument(pnfsMessage instanceof PnfsCreateSymLinkMessage);
String destination = ((PnfsCreateSymLinkMessage) pnfsMessage).getDestination();
LOGGER.info("create symlink {} to {}", path, destination);
checkRestrictionOnParent(pnfsMessage, MANAGE);
pnfsId = _nameSpaceProvider.createSymLink(subject, path, destination, assign);
pnfsMessage.setPnfsId(pnfsId);
break;
default:
throw new IllegalArgumentException("Unsupported type: " + type);
}
pnfsMessage.setFileAttributes(attrs);
pnfsMessage.setSucceeded();
} catch (CacheException e) {
pnfsMessage.setFailed(e.getRc(), e.getMessage());
} catch (RuntimeException e) {
LOGGER.error("Bug found when creating entry:", e);
pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
}
}
Aggregations