summaryrefslogtreecommitdiffstats
path: root/sched
diff options
context:
space:
mode:
authorJean-Philippe Lesot <jplesot@google.com>2015-03-11 10:50:55 +0100
committerJean-Philippe Lesot <jplesot@google.com>2015-03-11 10:50:55 +0100
commita6ad00e946f9efa9fcaad7ebff51e125a224e4b3 (patch)
treeadc1860f2496d58b222d8008a6a83405ddafe472 /sched
parent14f66d21a64021d5492c56aff5055e5e7382dfd4 (diff)
downloadtoolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.zip
toolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.tar.gz
toolchain_jack-a6ad00e946f9efa9fcaad7ebff51e125a224e4b3.tar.bz2
Start support of a small server for Jack compilation
Change-Id: I38d410565da4f480c60cdd9405603eebaa2d9938
Diffstat (limited to 'sched')
-rw-r--r--sched/src/com/android/sched/util/file/AbstractStreamFile.java4
-rw-r--r--sched/src/com/android/sched/util/file/Directory.java2
-rw-r--r--sched/src/com/android/sched/util/file/FileOrDirectory.java38
-rw-r--r--sched/src/com/android/sched/util/file/OutputStreamFile.java23
4 files changed, 64 insertions, 3 deletions
diff --git a/sched/src/com/android/sched/util/file/AbstractStreamFile.java b/sched/src/com/android/sched/util/file/AbstractStreamFile.java
index 2a680d4..6bd4b94 100644
--- a/sched/src/com/android/sched/util/file/AbstractStreamFile.java
+++ b/sched/src/com/android/sched/util/file/AbstractStreamFile.java
@@ -127,8 +127,8 @@ public abstract class AbstractStreamFile extends FileOrDirectory {
throw new NoSuchFileException(location);
}
- // Check it is a file
- if (!file.isFile()) {
+ // Check if it is not a Directory
+ if (file.isDirectory()) {
throw new NotFileException(location);
}
}
diff --git a/sched/src/com/android/sched/util/file/Directory.java b/sched/src/com/android/sched/util/file/Directory.java
index 55b30da..2d7f3ae 100644
--- a/sched/src/com/android/sched/util/file/Directory.java
+++ b/sched/src/com/android/sched/util/file/Directory.java
@@ -96,7 +96,7 @@ public class Directory extends FileOrDirectory {
throw new NoSuchFileException(location);
}
- // Check directory
+ // Check if it is a directory
if (!file.isDirectory()) {
throw new NotDirectoryException(location);
}
diff --git a/sched/src/com/android/sched/util/file/FileOrDirectory.java b/sched/src/com/android/sched/util/file/FileOrDirectory.java
index dde0146..c7d7dca 100644
--- a/sched/src/com/android/sched/util/file/FileOrDirectory.java
+++ b/sched/src/com/android/sched/util/file/FileOrDirectory.java
@@ -125,6 +125,44 @@ public abstract class FileOrDirectory implements HasLocation {
}
}
+
+ public static void unsetPermissions(@Nonnull File file, @Nonnull Location location,
+ int permissions, @Nonnull FileOrDirectory.ChangePermission change)
+ throws CannotSetPermissionException {
+ if (change != ChangePermission.NOCHANGE) {
+ // Set access
+ if ((permissions & Permission.READ) != 0) {
+ if (file.setReadable(false, change == ChangePermission.OWNER)) {
+ logger.log(Level.FINE, "Clear readable permission to {0} (''{1}'')",
+ new Object[] {location.getDescription(), file.getAbsoluteFile()});
+ } else {
+ throw new CannotSetPermissionException(location, Permission.READ,
+ change);
+ }
+ }
+
+ if ((permissions & Permission.WRITE) != 0) {
+ if (file.setWritable(false, change == ChangePermission.OWNER)) {
+ logger.log(Level.FINE, "Clear writable permission to {0} (''{1}'')",
+ new Object[] {location.getDescription(), file.getAbsoluteFile()});
+ } else {
+ throw new CannotSetPermissionException(location, Permission.WRITE,
+ change);
+ }
+ }
+
+ if ((permissions & Permission.EXECUTE) != 0) {
+ if (file.setExecutable(false, change == ChangePermission.OWNER)) {
+ logger.log(Level.FINE, "Clear executable permission to {0} (''{1}'')",
+ new Object[] {location.getDescription(), file.getAbsoluteFile()});
+ } else {
+ throw new CannotSetPermissionException(location, Permission.EXECUTE,
+ change);
+ }
+ }
+ }
+ }
+
public static void checkPermissions(@Nonnull File file, @Nonnull Location location,
int permissions) throws WrongPermissionException {
if ((permissions & Permission.READ) != 0) {
diff --git a/sched/src/com/android/sched/util/file/OutputStreamFile.java b/sched/src/com/android/sched/util/file/OutputStreamFile.java
index 055869b..6956ba1 100644
--- a/sched/src/com/android/sched/util/file/OutputStreamFile.java
+++ b/sched/src/com/android/sched/util/file/OutputStreamFile.java
@@ -83,6 +83,29 @@ public class OutputStreamFile extends AbstractStreamFile {
this.append = false;
}
+ /**
+ * Creates a new instance of {@link OutputStreamFile} assuming the file must exist, without
+ * modifying its permissions. It will be overwritten.
+ */
+ public OutputStreamFile(@Nonnull String name)
+ throws WrongPermissionException, NotFileException {
+ super(name, null);
+
+ try {
+ performChecks(Existence.MUST_EXIST, Permission.WRITE, ChangePermission.NOCHANGE);
+ } catch (NoSuchFileException e) {
+ throw new AssertionError(e);
+ } catch (FileAlreadyExistsException e) {
+ throw new AssertionError(e);
+ } catch (CannotSetPermissionException e) {
+ throw new AssertionError(e);
+ } catch (CannotCreateFileException e) {
+ throw new AssertionError(e);
+ }
+
+ this.append = false;
+ }
+
@Nonnull
private static final Location STANDARD_OUTPUT_LOCATION = new StandardOutputLocation();
@Nonnull