Skip to content

Commit

Permalink
[WFLY-11357] add priv block to FileSystemXAResourceRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
baranowb committed Jan 2, 2019
1 parent e03bcb0 commit bf1cd96
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -17,6 +17,8 @@
*/
package org.wildfly.transaction.client.provider.jboss;

import static java.security.AccessController.doPrivileged;

import org.wildfly.common.annotation.NotNull;
import org.wildfly.transaction.client.LocalTransaction;
import org.wildfly.transaction.client.SimpleXid;
Expand All @@ -39,6 +41,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -204,14 +209,20 @@ private final class XAResourceRegistryFile extends XAResourceRegistry {
* @throws SystemException if the there was a problem when creating the recovery file in file system
*/
XAResourceRegistryFile(Xid xid) throws SystemException {
xaRecoveryPath.toFile().mkdir(); // create dir if non existent

final String xidString = SimpleXid.of(xid).toHexString('_');
this.filePath = xaRecoveryPath.resolve(xidString);
openFilePaths.add(xidString);

try {
fileChannel = FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW);
fileChannel = doPrivileged((PrivilegedExceptionAction<FileChannel>) () -> {
xaRecoveryPath.toFile().mkdir(); // create dir if non existent
return FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW);
});
openFilePaths.add(xidString);
fileChannel.lock();
Log.log.xaResourceRecoveryFileCreated(filePath);
} catch (PrivilegedActionException e) {
throw Log.log.createXAResourceRecoveryFileFailed(filePath, (IOException)e.getCause());
} catch (IOException e) {
throw Log.log.createXAResourceRecoveryFileFailed(filePath, e);
}
Expand Down

0 comments on commit bf1cd96

Please sign in to comment.