Renamed PosixFile to PosixFiles
This commit is contained in:
@@ -152,7 +152,7 @@ configurations {
|
|||||||
def deployer = uploadJni.repositories.mavenDeployer
|
def deployer = uploadJni.repositories.mavenDeployer
|
||||||
|
|
||||||
binaries.withType(SharedLibraryBinary) { binary ->
|
binaries.withType(SharedLibraryBinary) { binary ->
|
||||||
if (!buildable) {
|
if (!buildable || targetPlatform.operatingSystem.name == 'linux' && targetPlatform.architecture.name != System.properties['os.arch']) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import java.io.File;
|
|||||||
* Functions to query and modify a file's POSIX meta-data.
|
* Functions to query and modify a file's POSIX meta-data.
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public interface PosixFile extends NativeIntegration {
|
public interface PosixFiles extends NativeIntegration {
|
||||||
/**
|
/**
|
||||||
* Sets the mode for the given file.
|
* Sets the mode for the given file.
|
||||||
*
|
*
|
||||||
@@ -17,12 +17,12 @@
|
|||||||
package net.rubygrapefruit.platform.internal;
|
package net.rubygrapefruit.platform.internal;
|
||||||
|
|
||||||
import net.rubygrapefruit.platform.NativeException;
|
import net.rubygrapefruit.platform.NativeException;
|
||||||
import net.rubygrapefruit.platform.PosixFile;
|
import net.rubygrapefruit.platform.PosixFiles;
|
||||||
import net.rubygrapefruit.platform.internal.jni.PosixFileFunctions;
|
import net.rubygrapefruit.platform.internal.jni.PosixFileFunctions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class DefaultPosixFile implements PosixFile {
|
public class DefaultPosixFiles implements PosixFiles {
|
||||||
public void setMode(File file, int perms) {
|
public void setMode(File file, int perms) {
|
||||||
FunctionResult result = new FunctionResult();
|
FunctionResult result = new FunctionResult();
|
||||||
PosixFileFunctions.chmod(file.getPath(), perms, result);
|
PosixFileFunctions.chmod(file.getPath(), perms, result);
|
||||||
@@ -41,7 +41,6 @@ public class DefaultPosixFile implements PosixFile {
|
|||||||
return stat.mode;
|
return stat.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String readLink(File link) throws NativeException {
|
public String readLink(File link) throws NativeException {
|
||||||
FunctionResult result = new FunctionResult();
|
FunctionResult result = new FunctionResult();
|
||||||
String contents = PosixFileFunctions.readlink(link.getPath(), result);
|
String contents = PosixFileFunctions.readlink(link.getPath(), result);
|
||||||
@@ -51,7 +50,6 @@ public class DefaultPosixFile implements PosixFile {
|
|||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void symlink(File link, String contents) throws NativeException {
|
public void symlink(File link, String contents) throws NativeException {
|
||||||
FunctionResult result = new FunctionResult();
|
FunctionResult result = new FunctionResult();
|
||||||
PosixFileFunctions.symlink(link.getPath(), contents, result);
|
PosixFileFunctions.symlink(link.getPath(), contents, result);
|
||||||
@@ -137,8 +137,8 @@ public abstract class Platform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
|
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
|
||||||
if (type.equals(PosixFile.class)) {
|
if (type.equals(PosixFiles.class)) {
|
||||||
return type.cast(new DefaultPosixFile());
|
return type.cast(new DefaultPosixFiles());
|
||||||
}
|
}
|
||||||
if (type.equals(Process.class)) {
|
if (type.equals(Process.class)) {
|
||||||
return type.cast(new WrapperProcess(new DefaultProcess(), false));
|
return type.cast(new WrapperProcess(new DefaultProcess(), false));
|
||||||
|
|||||||
@@ -1,129 +1,129 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 Adam Murdoch
|
* Copyright 2012 Adam Murdoch
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.rubygrapefruit.platform
|
package net.rubygrapefruit.platform
|
||||||
|
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
import spock.lang.IgnoreIf
|
import spock.lang.IgnoreIf
|
||||||
import net.rubygrapefruit.platform.internal.Platform
|
import net.rubygrapefruit.platform.internal.Platform
|
||||||
|
|
||||||
@IgnoreIf({Platform.current().windows})
|
@IgnoreIf({Platform.current().windows})
|
||||||
class PosixFileTest extends Specification {
|
class PosixFilesTest extends Specification {
|
||||||
@Rule TemporaryFolder tmpDir
|
@Rule TemporaryFolder tmpDir
|
||||||
final PosixFile file = Native.get(PosixFile.class)
|
final PosixFiles file = Native.get(PosixFiles.class)
|
||||||
|
|
||||||
def "caches file instance"() {
|
def "caches file instance"() {
|
||||||
expect:
|
expect:
|
||||||
Native.get(PosixFile.class) == file
|
Native.get(PosixFiles.class) == file
|
||||||
}
|
}
|
||||||
|
|
||||||
def "can set mode on a file"() {
|
def "can set mode on a file"() {
|
||||||
def testFile = tmpDir.newFile(fileName)
|
def testFile = tmpDir.newFile(fileName)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.setMode(testFile, 0740)
|
file.setMode(testFile, 0740)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
file.getMode(testFile) == 0740
|
file.getMode(testFile) == 0740
|
||||||
|
|
||||||
where:
|
where:
|
||||||
fileName << ["test.txt", "test\u03b1\u2295.txt"]
|
fileName << ["test.txt", "test\u03b1\u2295.txt"]
|
||||||
}
|
}
|
||||||
|
|
||||||
def "cannot set mode on file that does not exist"() {
|
def "cannot set mode on file that does not exist"() {
|
||||||
def testFile = new File(tmpDir.root, "unknown")
|
def testFile = new File(tmpDir.root, "unknown")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.setMode(testFile, 0660)
|
file.setMode(testFile, 0660)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
NativeException e = thrown()
|
NativeException e = thrown()
|
||||||
e.message == "Could not set UNIX mode on $testFile: could not chmod file (ENOENT errno 2)"
|
e.message == "Could not set UNIX mode on $testFile: could not chmod file (ENOENT errno 2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "cannot get mode on file that does not exist"() {
|
def "cannot get mode on file that does not exist"() {
|
||||||
def testFile = new File(tmpDir.root, "unknown")
|
def testFile = new File(tmpDir.root, "unknown")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.getMode(testFile)
|
file.getMode(testFile)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
NativeException e = thrown()
|
NativeException e = thrown()
|
||||||
e.message == "Could not get UNIX mode on $testFile: could not stat file (ENOENT errno 2)"
|
e.message == "Could not get UNIX mode on $testFile: could not stat file (ENOENT errno 2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "can create symbolic link"() {
|
def "can create symbolic link"() {
|
||||||
def testFile = new File(tmpDir.root, "test.txt")
|
def testFile = new File(tmpDir.root, "test.txt")
|
||||||
testFile.text = "hi"
|
testFile.text = "hi"
|
||||||
def symlinkFile = new File(tmpDir.root, "symlink")
|
def symlinkFile = new File(tmpDir.root, "symlink")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.symlink(symlinkFile, testFile.name)
|
file.symlink(symlinkFile, testFile.name)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
symlinkFile.file
|
symlinkFile.file
|
||||||
symlinkFile.text == "hi"
|
symlinkFile.text == "hi"
|
||||||
symlinkFile.canonicalFile == testFile.canonicalFile
|
symlinkFile.canonicalFile == testFile.canonicalFile
|
||||||
}
|
}
|
||||||
|
|
||||||
def "can read symbolic link"() {
|
def "can read symbolic link"() {
|
||||||
def symlinkFile = new File(tmpDir.root, "symlink")
|
def symlinkFile = new File(tmpDir.root, "symlink")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.symlink(symlinkFile, "target")
|
file.symlink(symlinkFile, "target")
|
||||||
|
|
||||||
then:
|
then:
|
||||||
file.readLink(symlinkFile) == "target"
|
file.readLink(symlinkFile) == "target"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "cannot read a symlink that does not exist"() {
|
def "cannot read a symlink that does not exist"() {
|
||||||
def symlinkFile = new File(tmpDir.root, "symlink")
|
def symlinkFile = new File(tmpDir.root, "symlink")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.readLink(symlinkFile)
|
file.readLink(symlinkFile)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
NativeException e = thrown()
|
NativeException e = thrown()
|
||||||
e.message == "Could not read symlink $symlinkFile: could not lstat file (ENOENT errno 2)"
|
e.message == "Could not read symlink $symlinkFile: could not lstat file (ENOENT errno 2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "cannot read a symlink that is not a symlink"() {
|
def "cannot read a symlink that is not a symlink"() {
|
||||||
def symlinkFile = tmpDir.newFile("not-a-symlink.txt")
|
def symlinkFile = tmpDir.newFile("not-a-symlink.txt")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.readLink(symlinkFile)
|
file.readLink(symlinkFile)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
NativeException e = thrown()
|
NativeException e = thrown()
|
||||||
e.message == "Could not read symlink $symlinkFile: could not readlink (errno 22)"
|
e.message == "Could not read symlink $symlinkFile: could not readlink (errno 22)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "can create and read symlink with unicode in its name"() {
|
def "can create and read symlink with unicode in its name"() {
|
||||||
def testFile = new File(tmpDir.root, "target\u03b2\u2295")
|
def testFile = new File(tmpDir.root, "target\u03b2\u2295")
|
||||||
testFile.text = 'hi'
|
testFile.text = 'hi'
|
||||||
def symlinkFile = new File(tmpDir.root, "symlink\u03b2\u2296")
|
def symlinkFile = new File(tmpDir.root, "symlink\u03b2\u2296")
|
||||||
|
|
||||||
when:
|
when:
|
||||||
file.symlink(symlinkFile, testFile.name)
|
file.symlink(symlinkFile, testFile.name)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
file.readLink(symlinkFile) == testFile.name
|
file.readLink(symlinkFile) == testFile.name
|
||||||
symlinkFile.file
|
symlinkFile.file
|
||||||
symlinkFile.canonicalFile == testFile.canonicalFile
|
symlinkFile.canonicalFile == testFile.canonicalFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user