Search in sources :

Example 1 with ProviderMismatchException

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);
    }
}
Also used : ProviderMismatchException(java.nio.file.ProviderMismatchException) IOException(java.io.IOException)

Example 2 with ProviderMismatchException

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) ProviderMismatchException(java.nio.file.ProviderMismatchException) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) MCRISO8601Date(org.mycore.datamodel.common.MCRISO8601Date) Date(java.util.Date) HashSet(java.util.HashSet)

Example 3 with ProviderMismatchException

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);
}
Also used : ProviderMismatchException(java.nio.file.ProviderMismatchException)

Example 4 with ProviderMismatchException

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());
}
Also used : ProviderMismatchException(java.nio.file.ProviderMismatchException)

Example 5 with ProviderMismatchException

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);
    }
}
Also used : FileSystem(java.nio.file.FileSystem) ProviderMismatchException(java.nio.file.ProviderMismatchException)

Aggregations

ProviderMismatchException (java.nio.file.ProviderMismatchException)5 IOException (java.io.IOException)1 FileSystem (java.nio.file.FileSystem)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)1 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1 MCRISO8601Date (org.mycore.datamodel.common.MCRISO8601Date)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1