99
* Tries to create the ancestor directories of file f. Throws
100
* an IOException if it can't be created (but not if it was
103
* @param eMsg - the message to use for the exception. null
104
* if the file name is to be used.
105
* @throws IOException if the directory can't be created and doesn't exist.
107
public static void createParentDir(File f, String eMsg) throws IOException {
108
File parent = f.getParentFile();
109
if (!parent.isDirectory() && !parent.mkdirs()) {
110
throw new IOException(R("RCantCreateDir",
111
eMsg == null ? parent : eMsg));
116
* Tries to create the ancestor directories of file f. Throws
117
* an IOException if it can't be created (but not if it was
120
* @throws IOException if the directory can't be created and doesn't exist.
122
public static void createParentDir(File f) throws IOException {
123
createParentDir(f, null);
127
* Tries to delete file f. If the file exists but couldn't be deleted,
128
* print an error message to stderr with the file name, or eMsg if eMsg
130
* @param f the file to be deleted
131
* @param eMsg the message to print on failure (or null to print the
134
public static void deleteWithErrMesg(File f, String eMsg) {
137
System.err.println(R("RCantDeleteFile", eMsg == null ? f : eMsg));
143
* Tries to delete file f. If the file exists but couldn't be deleted,
144
* print an error message to stderr with the file name.
145
* @param f the file to be deleted
147
public static void deleteWithErrMesg(File f) {
148
deleteWithErrMesg(f, null);
99
152
* Creates a new file or directory with minimum permissions. The file is not
100
153
* readable or writable by anyone other than the owner. If writeableByOnwer
101
154
* is false, even the owner can not write to it. If isDir is true, then the
122
175
// remove all permissions
123
tempFile.setExecutable(false, false);
124
tempFile.setReadable(false, false);
125
tempFile.setWritable(false, false);
176
if (!tempFile.setExecutable(false, false)) {
177
throw new IOException(R("RRemoveXPermFailed", tempFile));
179
if (!tempFile.setReadable(false, false)) {
180
throw new IOException(R("RRemoveRPermFailed", tempFile));
182
if (!tempFile.setWritable(false, false)) {
183
throw new IOException(R("RRemoveWPermFailed", tempFile));
127
186
// allow owner to read
128
tempFile.setReadable(true, true);
187
if (!tempFile.setReadable(true, true)) {
188
throw new IOException(R("RGetRPermFailed", tempFile));
130
191
// allow owner to write
131
if (writableByOwner) {
132
tempFile.setWritable(true, true);
192
if (writableByOwner && !tempFile.setWritable(true, true)) {
193
throw new IOException(R("RGetWPermFailed", tempFile));
135
196
// allow owner to enter directories
137
tempFile.setExecutable(true, true);
197
if (isDir && !tempFile.setExecutable(true, true)) {
198
throw new IOException(R("RGetXPermFailed", tempFile));
140
201
// rename this file. Unless the file is moved/renamed, any program that