提交 1889def4 编写于 作者: R robm

6931128: (spec) File attribute tests fail when run as root.

Reviewed-by: alanb
上级 39996608
/*
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -711,7 +711,10 @@ public class File
/**
* Tests whether the application can read the file denoted by this
* abstract pathname.
* abstract pathname. On some platforms it may be possible to start the
* Java virtual machine with special privileges that allow it to read
* files that are marked as unreadable. Consequently this method may return
* {@code true} even though the file does not have read permissions.
*
* @return <code>true</code> if and only if the file specified by this
* abstract pathname exists <em>and</em> can be read by the
......@@ -732,7 +735,10 @@ public class File
/**
* Tests whether the application can modify the file denoted by this
* abstract pathname.
* abstract pathname. On some platforms it may be possible to start the
* Java virtual machine with special privileges that allow it to modify
* files that are marked read-only. Consequently this method may return
* {@code true} even though the file is marked read-only.
*
* @return <code>true</code> if and only if the file system actually
* contains a file denoted by this abstract pathname <em>and</em>
......@@ -1352,8 +1358,10 @@ public class File
/**
* Marks the file or directory named by this abstract pathname so that
* only read operations are allowed. After invoking this method the file
* or directory is guaranteed not to change until it is either deleted or
* marked to allow write access. Whether or not a read-only file or
* or directory will not change until it is either deleted or marked
* to allow write access. On some platforms it may be possible to start the
* Java virtual machine with special privileges that allow it to modify
* files that are marked read-only. Whether or not a read-only file or
* directory may be deleted depends upon the underlying system.
*
* @return <code>true</code> if and only if the operation succeeded;
......@@ -1376,7 +1384,9 @@ public class File
/**
* Sets the owner's or everybody's write permission for this abstract
* pathname.
* pathname. On some platforms it may be possible to start the Java virtual
* machine with special privileges that allow it to modify files that
* disallow write operations.
*
* <p> The {@link java.nio.file.Files} class defines methods that operate on
* file attributes including file permissions. This may be used when finer
......@@ -1414,7 +1424,9 @@ public class File
/**
* A convenience method to set the owner's write permission for this abstract
* pathname.
* pathname. On some platforms it may be possible to start the Java virtual
* machine with special privileges that allow it to modify files that
* disallow write operations.
*
* <p> An invocation of this method of the form <tt>file.setWritable(arg)</tt>
* behaves in exactly the same way as the invocation
......@@ -1443,7 +1455,9 @@ public class File
/**
* Sets the owner's or everybody's read permission for this abstract
* pathname.
* pathname. On some platforms it may be possible to start the Java virtual
* machine with special privileges that allow it to read files that are
* marked as unreadable.
*
* <p> The {@link java.nio.file.Files} class defines methods that operate on
* file attributes including file permissions. This may be used when finer
......@@ -1484,7 +1498,9 @@ public class File
/**
* A convenience method to set the owner's read permission for this abstract
* pathname.
* pathname. On some platforms it may be possible to start the Java virtual
* machine with special privileges that allow it to read files that that are
* marked as unreadable.
*
* <p>An invocation of this method of the form <tt>file.setReadable(arg)</tt>
* behaves in exactly the same way as the invocation
......@@ -1516,7 +1532,9 @@ public class File
/**
* Sets the owner's or everybody's execute permission for this abstract
* pathname.
* pathname. On some platforms it may be possible to start the Java virtual
* machine with special privileges that allow it to execute files that are
* not marked executable.
*
* <p> The {@link java.nio.file.Files} class defines methods that operate on
* file attributes including file permissions. This may be used when finer
......@@ -1556,8 +1574,10 @@ public class File
}
/**
* A convenience method to set the owner's execute permission for this abstract
* pathname.
* A convenience method to set the owner's execute permission for this
* abstract pathname. On some platforms it may be possible to start the Java
* virtual machine with special privileges that allow it to execute files
* that are not marked executable.
*
* <p>An invocation of this method of the form <tt>file.setExcutable(arg)</tt>
* behaves in exactly the same way as the invocation
......@@ -1589,7 +1609,10 @@ public class File
/**
* Tests whether the application can execute the file denoted by this
* abstract pathname.
* abstract pathname. On some platforms it may be possible to start the
* Java virtual machine with special privileges that allow it to execute
* files that are not marked executable. Consequently this method may return
* {@code true} even though the file does not have execute permissions.
*
* @return <code>true</code> if and only if the abstract pathname exists
* <em>and</em> the application is allowed to execute the file
......
/*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -25,7 +25,7 @@
@bug 4165666 4203706 4288670 4290024
@summary Basic heartbeat test for File methods that access the filesystem
@build Basic
@build Basic Util
@run shell basic.sh
*/
......@@ -73,7 +73,7 @@ public class Basic {
if (!f.isFile()) fail(f, "is not a file");
if (f.isDirectory()) fail(f, "is a directory");
if (!f.canRead()) fail(f, "is not readable");
if (f.canWrite() != writeable)
if (!Util.isPrivileged() && f.canWrite() != writeable)
fail(f, writeable ? "is not writeable" : "is writeable");
int rwLen = 6;
if (f.length() != length) fail(f, "has wrong length");
......
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -24,6 +24,8 @@
/* @test
@bug 4167472 5097703 6216563 6284003 6728842 6464744
@summary Basic test for setWritable/Readable/Executable methods
@build SetAccess Util
@run main SetAccess
*/
import java.io.*;
......@@ -32,6 +34,11 @@ import java.nio.file.attribute.*;
public class SetAccess {
public static void main(String[] args) throws Exception {
if (Util.isPrivileged()) {
System.out.println("Unable to test file permissions when running with privileges");
return;
}
File d = new File(System.getProperty("test.dir", "."));
File f = new File(d, "x.SetAccessPermission");
......
/*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -24,6 +24,8 @@
/* @test
@bug 4091757 4939819 6728842
@summary Basic test for setReadOnly method
@build SetReadOnly Util
@run main SetReadOnly
*/
import java.io.*;
......@@ -32,6 +34,11 @@ import java.io.*;
public class SetReadOnly {
public static void main(String[] args) throws Exception {
if (Util.isPrivileged()) {
System.out.println("Unable to test file permissions when running with privileges");
return;
}
File d = new File(System.getProperty("test.dir", "."));
File f = new File(d, "x.SetReadOnly");
......
/*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -24,6 +24,8 @@
/* @test
* @bug 6595866
* @summary Test java.io.File operations with sym links
* @build SymLinks Util
* @run main SymLinks
*/
import java.io.*;
......@@ -338,7 +340,7 @@ public class SymLinks {
assertTrue(link2link2file.canRead());
assertTrue(link2link2file.canWrite());
if (file.setReadOnly()) {
if (!Util.isPrivileged() && file.setReadOnly()) {
assertFalse(file.canWrite());
assertFalse(link2file.canWrite());
assertFalse(link2link2file.canWrite());
......
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.File;
/**
* Utility class used by tests for java.io.File.
*/
class Util {
private Util() { }
/**
* Returns {@code true} if the Java virtual machine is running with
* privileges (loosely defined here as have write access to /etc/passwd).
*/
static boolean isPrivileged() {
String osname = System.getProperty("os.name");
if (osname.startsWith("Windows"))
return false;
return (new File("/etc/passwd")).canWrite();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册