use of java.nio.file.ProviderMismatchException in project jdk8u_jdk by JetBrains.
the class WindowsAclFileAttributeView method setOwner.
@Override
public void setOwner(UserPrincipal obj) throws IOException {
if (obj == null)
throw new NullPointerException("'owner' is null");
if (!(obj instanceof WindowsUserPrincipals.User))
throw new ProviderMismatchException();
WindowsUserPrincipals.User owner = (WindowsUserPrincipals.User) obj;
// permission check
checkAccess(file, false, true);
// SetFileSecurity does not follow links so when following links we
// need the final target
String path = WindowsLinkSupport.getFinalPath(file, followLinks);
// ConvertStringSidToSid allocates memory for SID so must invoke
// LocalFree to free it when we are done
long pOwner = 0L;
try {
pOwner = ConvertStringSidToSid(owner.sidString());
} catch (WindowsException x) {
throw new IOException("Failed to get SID for " + owner.getName() + ": " + x.errorString());
}
// owner information and update the file.
try {
NativeBuffer buffer = NativeBuffers.getNativeBuffer(SIZEOF_SECURITY_DESCRIPTOR);
try {
InitializeSecurityDescriptor(buffer.address());
SetSecurityDescriptorOwner(buffer.address(), pOwner);
// may need SeRestorePrivilege to set the owner
WindowsSecurity.Privilege priv = WindowsSecurity.enablePrivilege("SeRestorePrivilege");
try {
SetFileSecurity(path, OWNER_SECURITY_INFORMATION, buffer.address());
} finally {
priv.drop();
}
} catch (WindowsException x) {
x.rethrowAsIOException(file);
} finally {
buffer.release();
}
} finally {
LocalFree(pOwner);
}
}
use of java.nio.file.ProviderMismatchException in project mycore by MyCoRe-Org.
the class MCRSolrFileIndexBaseAccumulator method accumulate.
@Override
public void accumulate(SolrInputDocument doc, Path input, BasicFileAttributes attr) throws IOException {
doc.setField("id", input.toUri().toString());
String absolutePath = '/' + input.subpath(0, input.getNameCount()).toString();
try {
// check if this is an MCRPath -> more metadata
MCRPath mcrPath = MCRPath.toMCRPath(input);
MCRObjectID mcrObjID = MCRMetadataManager.getObjectId(MCRObjectID.getInstance(mcrPath.getOwner()), 10, TimeUnit.SECONDS);
if (mcrObjID == null) {
LOGGER.warn("Could not determine MCRObject for file {}", absolutePath);
doc.setField("returnId", mcrPath.getOwner());
} else {
doc.setField("returnId", mcrObjID.toString());
doc.setField("objectProject", mcrObjID.getProjectId());
}
String ownerID = mcrPath.getOwner();
doc.setField("derivateID", ownerID);
doc.setField("derivateModified", getDerivateModified(ownerID));
Collection<MCRCategoryID> linksFromReference = MCRCategLinkServiceFactory.getInstance().getLinksFromReference(new MCRCategLinkReference(mcrPath));
HashSet<MCRCategoryID> linkedCategories = new HashSet<>(linksFromReference);
for (MCRCategoryID category : linksFromReference) {
for (MCRCategory parent : CATEGORY_DAO.getParents(category)) {
linkedCategories.add(parent.getId());
}
}
for (MCRCategoryID category : linkedCategories) {
doc.addField("fileCategory", category.toString());
}
} catch (ProviderMismatchException e) {
LOGGER.warn("Cannot build all fields as input is not an instance of MCRPath: {}", input);
}
doc.setField("objectType", "data_file");
doc.setField("fileName", input.getFileName().toString());
doc.setField("filePath", absolutePath);
doc.setField("stream_size", attr.size());
doc.setField("stream_name", absolutePath);
doc.setField("stream_source_info", input.toString());
doc.setField("stream_content_type", MCRContentTypes.probeContentType(input));
doc.setField("extension", Files.getFileExtension(input.getFileName().toString()));
MCRISO8601Date iDate = new MCRISO8601Date();
iDate.setDate(new Date(attr.lastModifiedTime().toMillis()));
doc.setField("modified", iDate.getISOString());
}
use of java.nio.file.ProviderMismatchException in project j2objc by google.
the class ProviderMismatchExceptionTest method test_constructor.
public void test_constructor() {
ProviderMismatchException exception = new ProviderMismatchException();
assertEquals(null, exception.getMessage());
assertTrue(exception instanceof IllegalArgumentException);
}
use of java.nio.file.ProviderMismatchException in project j2objc by google.
the class ProviderMismatchExceptionTest method test_constructor$String.
public void test_constructor$String() {
String testString = "testString";
ProviderMismatchException exception = new ProviderMismatchException(testString);
assertEquals(testString, exception.getMessage());
}
use of java.nio.file.ProviderMismatchException in project cryptofs by cryptomator.
the class CryptoFileSystemProvider method fileSystem.
private CryptoFileSystemImpl fileSystem(Path path) {
FileSystem fileSystem = path.getFileSystem();
if (fileSystem.provider() == this) {
CryptoFileSystemImpl cryptoFileSystem = (CryptoFileSystemImpl) fileSystem;
cryptoFileSystem.assertOpen();
return cryptoFileSystem;
} else {
throw new ProviderMismatchException("Used a path from provider " + fileSystem.provider() + " with provider " + this);
}
}
Aggregations