package org.xbib.files.ftp.fs.test.server;

import org.xbib.files.ftp.mock.fake.filesystem.FileSystemEntry;
import org.xbib.files.ftp.mock.fake.filesystem.UnixDirectoryListingFormatter;

/**
 * An extended version of {@link UnixDirectoryListingFormatter} that supports symbolic links.
 */
public class ExtendedUnixDirectoryListingFormatter extends UnixDirectoryListingFormatter {

    @Override
    public String format(FileSystemEntry fileSystemEntry) {
        String formatted = super.format(fileSystemEntry);
        if (fileSystemEntry instanceof SymbolicLinkEntry) {
            SymbolicLinkEntry symLink = (SymbolicLinkEntry) fileSystemEntry;
            formatted = "l" + formatted.substring(1) + " -> " + symLink.getTarget().getPath();
        }
        return formatted;
    }
}
