/** * Method called locally to the repository during {@link #rawAccess()}. Only the remoteable fields * should be accessed during this method call since this will be a copy of the object originally * called. * * @param abstractRepositoryI * @param servant * @param __current */ public void local( AbstractRepositoryI abstractRepositoryI, PublicRepositoryI servant, Current __current) throws Exception { if ("touch".equals(command)) { for (String arg : args) { final CheckedPath checked = servant.checkPath(parse(arg), null, __current); if (!checked.exists()) { final CheckedPath parent = checked.parent(); if (!(parent.isDirectory() || checked.parent().mkdirs())) { throw new RepositoryException(null, null, "cannot create directory: " + parent); } final FileBuffer buffer = checked.getFileBuffer("rw"); buffer.write(ByteBuffer.allocate(0)); buffer.close(); } else if (!checked.markModified()) { throw new RepositoryException(null, null, "cannot touch file: " + checked); } } } else if ("mkdir".equals(command)) { boolean parents = false; for (String arg : args) { if ("-p".equals(arg)) { parents = true; continue; } final CheckedPath checked = servant.checkPath(parse(arg), null, __current); if (parents) { checked.mkdirs(); } else { checked.mkdir(); } } } else if ("rm".equals(command)) { if (args.size() == 1) { final CheckedPath checked = servant.checkPath(parse(args.get(0)), null, __current); if (!checked.delete()) { throw new omero.grid.FileDeleteException( null, null, "Delete file failed: " + args.get(0)); } } else { throw new omero.ApiUsageException( null, null, "Command: " + command + " takes just one argument"); } } else if ("checksum".equals(command)) { if (args.size() == 3) { final String checksumType = args.get(0); final ChecksumAlgorithm algo = ChecksumAlgorithmMapper.getChecksumAlgorithm(checksumType); final String expectedHash = args.get(1); final CheckedPath checked = servant.checkPath(parse(args.get(2)), algo, __current); final String currentHash = checked.hash(); if (!currentHash.equals(expectedHash)) { // TODO: ADD ANNOTATION TO DATABASE HERE! throw new omero.ResourceError( null, null, String.format( "Checksum mismatch (%s): expected=%s found=%s", checksumType, expectedHash, currentHash)); } } else { throw new omero.ApiUsageException( null, null, "'checksum' requires HASHER HASH FILEPATH, not: " + args.toString()); } } else { throw new omero.ApiUsageException(null, null, "Unknown command: " + command); } }