RemoveReadOnlyNode.java revision 1568
1568N/A/*
1568N/A * Copyright 2009 Sun Microsystems, Inc. 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 *
1568N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1568N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1568N/A * have any questions.
1568N/A */
1568N/A
1568N/A
1568N/A/* @test
1568N/A @bug 6178148
1568N/A @summary check if wrong exception gets thrown if one of the child
1568N/A nodes is readonly on underlying filesystem when node is
1568N/A being removed.
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}