private String ensureDirs()

in wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java [404:475]


    private String ensureDirs(
            ScmProvider scmProvider,
            ScmRepository scmRepository,
            String targetName,
            Resource resource,
            boolean recursiveArg)
            throws TransferFailedException, IOException {
        if (checkoutDirectory == null) {
            checkoutDirectory = createCheckoutDirectory();
        }

        String target = targetName;

        // totally ignore scmRepository parent stuff since that is not supported by all scms.
        // Instead, assume that that url exists. If not, then that's an error.
        // Check whether targetName, which is a relative path into the scm, exists.
        // If it doesn't, check the parent, etc.

        boolean recursive = recursiveArg;

        for (; ; ) {
            try {
                ScmResult res = tryPartialCheckout(target, recursive);
                if (!res.isSuccess()) {
                    throw new ScmException(
                            "command failed: " + res.getCommandOutput().trim());
                }
                break;
            } catch (ScmException e) {
                recursive = false;
                if (partCOSubdir.length() == 0) {
                    fireTransferError(resource, e, TransferEvent.REQUEST_GET);

                    throw new TransferFailedException("Error checking out: " + e.getMessage(), e);
                }
                target = getDirname(target);
            }
        }

        // now create the subdirs in target, if it's a parent of targetName

        String res =
                partCOSubdir.length() >= targetName.length() ? "" : targetName.substring(partCOSubdir.length()) + '/';

        ArrayList<File> createdDirs = new ArrayList<>();
        File deepDir = new File(checkoutDirectory, res);

        boolean added = false;
        try {
            mkdirsThrow(deepDir, createdDirs);
            if (createdDirs.size() != 0) {
                File topNewDir = createdDirs.get(0);
                String relTopNewDir = topNewDir
                        .getPath()
                        .substring(checkoutDirectory.getPath().length() + 1)
                        .replace('\\', '/');

                addFiles(scmProvider, scmRepository, checkoutDirectory, relTopNewDir);
                added = true;
            }
        } catch (ScmException e) {
            fireTransferError(resource, e, TransferEvent.REQUEST_PUT);

            throw new TransferFailedException("Failed to add directory " + createdDirs.get(0) + " to working copy", e);
        } finally {
            if (!added && createdDirs.size() != 0) {
                FileUtils.deleteDirectory(createdDirs.get(0));
            }
        }

        return res;
    }