protected void writeDir()

in wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/ScpCommand.java [321:383]


    protected void writeDir( String header, SshFile path )
        throws IOException
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( "Writing dir {}", path );
        }
        if ( !header.startsWith( "D" ) )
        {
            throw new IOException( "Expected a D message but got '" + header + "'" );
        }

        String perms = header.substring( 1, 5 );
        int length = Integer.parseInt( header.substring( 6, header.indexOf( ' ', 6 ) ) );
        String name = header.substring( header.indexOf( ' ', 6 ) + 1 );

        if ( length != 0 )
        {
            throw new IOException( "Expected 0 length for directory but got " + length );
        }
        SshFile file;
        if ( path.doesExist() && path.isDirectory() )
        {
            file = root.getFile( path, name );
        }
        else if ( !path.doesExist() && path.getParentFile().doesExist() && path.getParentFile().isDirectory() )
        {
            file = path;
        }
        else
        {
            throw new IOException( "Can not write to " + path );
        }
        if ( !( file.doesExist() && file.isDirectory() ) && !file.mkdir() )
        {
            throw new IOException( "Could not create directory " + file );
        }

        ack();

        for (; ; )
        {
            header = readLine();
            if ( header.startsWith( "C" ) )
            {
                writeFile( header, file );
            }
            else if ( header.startsWith( "D" ) )
            {
                writeDir( header, file );
            }
            else if ( header.equals( "E" ) )
            {
                ack();
                break;
            }
            else
            {
                throw new IOException( "Unexpected message: '" + header + "'" );
            }
        }

    }