1568N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1568N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1568N/A *
1568N/A * This code is free software; you can redistribute it and/or modify it
1568N/A * under the terms of the GNU General Public License version 2 only, as
1568N/A * published by the Free Software Foundation.
1568N/A *
1568N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1568N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1568N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1568N/A * version 2 for more details (a copy is included in the LICENSE file that
1568N/A * accompanied this code).
1568N/A *
1568N/A * You should have received a copy of the GNU General Public License version
1568N/A * 2 along with this work; if not, write to the Free Software Foundation,
1568N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1568N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1568N/A */
1568N/A
1568N/A
1568N/A/* @test
5853N/A * @bug 6178148 7197662
5853N/A * @summary check if wrong exception gets thrown if one of the child
5853N/A * nodes is readonly on underlying filesystem when node is
5853N/A * being removed.
5853N/A * @run main/othervm -Djava.util.prefs.userRoot=. RemoveReadOnlyNode
1568N/A */
1568N/A
1568N/Aimport java.io.*;
1568N/Aimport java.util.prefs.*;
1568N/A
1568N/Apublic class RemoveReadOnlyNode {
1568N/A public static void main(String[] args) throws Exception {
1568N/A String osName = System.getProperty("os.name");
1568N/A if (osName.startsWith("Windows"))
1568N/A return;
1568N/A Preferences root = Preferences.userRoot();
1568N/A Preferences node1 = root.node("node1");
1568N/A Preferences node1A = node1.node("node1A");
1568N/A Preferences node1B = node1.node("node1B");
1568N/A node1B.put("mykey", "myvalue");
1568N/A node1.flush();
1568N/A String node1BDirName = System.getProperty("user.home")
1568N/A + "/.java/.userPrefs"
1568N/A + "/node1/node1B";
1568N/A File node1BDir = new File(node1BDirName);
1568N/A node1BDir.setReadOnly();
1568N/A try {
1568N/A node1.removeNode();
1568N/A }
1568N/A catch (BackingStoreException ex) {
1568N/A //expected exception
1568N/A } finally {
1568N/A Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor();
1568N/A try {
1568N/A node1.removeNode();
1568N/A } catch (Exception e) {}
1568N/A }
1568N/A }
1568N/A}