Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP2:Update
gradle.36305
use-nio-files-createTempFile-rather-than-File-c...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File use-nio-files-createTempFile-rather-than-File-createTempFile.patch of Package gradle.36305
Index: gradle-4.4.1/subprojects/core/src/main/java/org/gradle/api/internal/file/DefaultTemporaryFileProvider.java =================================================================== --- gradle-4.4.1.orig/subprojects/core/src/main/java/org/gradle/api/internal/file/DefaultTemporaryFileProvider.java +++ gradle-4.4.1/subprojects/core/src/main/java/org/gradle/api/internal/file/DefaultTemporaryFileProvider.java @@ -23,13 +23,27 @@ import org.gradle.util.CollectionUtils; import org.gradle.util.GFileUtils; import javax.annotation.Nullable; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.util.EnumSet; public class DefaultTemporaryFileProvider implements TemporaryFileProvider, Serializable { private final Factory<File> baseDirFactory; + private static final FileAttribute[] TMPFILE_ATTRIBUTES = + new FileAttribute[] { + PosixFilePermissions.asFileAttribute(EnumSet.of(PosixFilePermission.OWNER_READ, + PosixFilePermission.OWNER_WRITE)) + }; + private static final FileAttribute[] NO_TMPFILE_ATTRIBUTES = new FileAttribute[0]; + public DefaultTemporaryFileProvider(final Factory<File> fileFactory) { this.baseDirFactory = fileFactory; } @@ -50,11 +64,17 @@ public class DefaultTemporaryFileProvide public File createTemporaryDirectory(@Nullable String prefix, @Nullable String suffix, @Nullable String... path) { File dir = new File(baseDirFactory.create(), CollectionUtils.join("/", path)); + File tmpDir; GFileUtils.mkdirs(dir); try { // TODO: This is not a great paradigm for creating a temporary directory. // See http://guava-libraries.googlecode.com/svn/tags/release08/javadoc/com/google/common/io/Files.html#createTempDir%28%29 for an alternative. - File tmpDir = File.createTempFile("gradle", "projectDir", dir); + final Path parentPath = dir.toPath(); + final PosixFileAttributeView parentPosixAttributes = + Files.getFileAttributeView(parentPath, PosixFileAttributeView.class); + tmpDir = Files.createTempFile(parentPath, prefix, suffix, + parentPosixAttributes != null ? TMPFILE_ATTRIBUTES : NO_TMPFILE_ATTRIBUTES) + .toFile(); tmpDir.delete(); tmpDir.mkdir(); return tmpDir; Index: gradle-4.4.1/subprojects/core/src/test/groovy/org/gradle/api/internal/file/DefaultTemporaryFileProviderTest.groovy =================================================================== --- gradle-4.4.1.orig/subprojects/core/src/test/groovy/org/gradle/api/internal/file/DefaultTemporaryFileProviderTest.groovy +++ gradle-4.4.1/subprojects/core/src/test/groovy/org/gradle/api/internal/file/DefaultTemporaryFileProviderTest.groovy @@ -15,8 +15,14 @@ */ package org.gradle.api.internal.file +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.util.Set; + import org.gradle.internal.Factory import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; import org.junit.Rule import spock.lang.Specification @@ -60,5 +66,13 @@ class DefaultTemporaryFileProviderTest e assert file.name.startsWith("prefix") assert file.name.endsWith("suffix") assert file.path.startsWith(new File(tmpDir.testDirectory, "foo/bar").path) + final PosixFileAttributeView attributes = + Files.getFileAttributeView(tmp1.toPath(), PosixFileAttributeView.class); + if (attributes != null) { + final Set<PosixFilePermission> perm = attributes.readAttributes().permissions(); + assertThat(perm, + containsInAnyOrder(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE)); + assertThat(perm, hasSize(2)); + } } }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor