01: /*
02: * Gruntspud
03: *
04: * Copyright (C) 2002 Brett Smith.
05: *
06: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public License
10: * as published by the Free Software Foundation; either version 2 of
11: * the License, or (at your option) any later version.
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU Library General Public License for more details.
16: *
17: * You should have received a copy of the GNU Library General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: */
21:
22: package gruntspud.file;
23:
24: import gruntspud.StreamSink;
25:
26: import java.io.File;
27: import java.io.IOException;
28: import java.util.ResourceBundle;
29:
30: import org.netbeans.lib.cvsclient.file.FileReadOnlyHandler;
31:
32: public class ChmodFileReadOnlyHandler implements FileReadOnlyHandler {
33: static ResourceBundle res = ResourceBundle
34: .getBundle("gruntspud.file.ResourceBundle");
35:
36: public void setFileReadOnly(File file, boolean readOnly)
37: throws IOException {
38: if (file == null) {
39: throw new IllegalArgumentException(res
40: .getString("fileMustNotBeNull")); // NOI18N
41: }
42:
43: try {
44: String[] arguments = { "chmod", readOnly ? "u-w" : "u+w",
45: file.getName() };
46: Process process = Runtime.getRuntime().exec(arguments,
47: null, file.getParentFile());
48: process = Runtime.getRuntime().exec(arguments, null,
49: file.getParentFile());
50: new StreamSink(process.getErrorStream(), true);
51: new StreamSink(process.getInputStream(), true);
52: } catch (Exception e) {
53: }
54: }
55: }
|