/** * Create directories in server as needed. They are created one at a time until the whole path * exists. * * @param dir path to be created in server from repository basedir * @throws IOException * @throws HttpException * @throws TransferFailedException */ protected void mkdirs(String dir) throws IOException { Repository repository = getRepository(); String basedir = repository.getBasedir(); String baseUrl = repository.getProtocol() + "://" + repository.getHost(); if (repository.getPort() != WagonConstants.UNKNOWN_PORT) { baseUrl += ":" + repository.getPort(); } // create relative path that will always have a leading and trailing slash String relpath = FileUtils.normalize(getPath(basedir, dir) + "/"); PathNavigator navigator = new PathNavigator(relpath); // traverse backwards until we hit a directory that already exists (OK/NOT_ALLOWED), or that we // were able to // create (CREATED), or until we get to the top of the path int status = SC_NULL; do { String url = baseUrl + "/" + navigator.getPath(); status = doMkCol(url); if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_METHOD_NOT_ALLOWED) { break; } } while (navigator.backward()); // traverse forward creating missing directories while (navigator.forward()) { String url = baseUrl + "/" + navigator.getPath(); status = doMkCol(url); if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) { throw new IOException("Unable to create collection: " + url + "; status code = " + status); } } }