Commit 08036e3f authored by Matija Obreza's avatar Matija Obreza

FTP: CanBeAnythingFile updated with date and dir/file type

parent 7c85407d
Pipeline #6178 passed with stage
in 2 minutes and 21 seconds
......@@ -18,6 +18,8 @@ package org.genesys.filerepository.service.ftp;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import org.apache.ftpserver.ftplet.FtpFile;
......@@ -28,20 +30,18 @@ import org.apache.ftpserver.ftplet.FtpFile;
public abstract class CanBeAnythingFile implements FtpFile {
/** The parent. */
private final String parent;
/** The name. */
private final String name;
private final Path path;
private long date = new Date().getTime();
protected boolean dir = false;
/**
* Instantiates a new can be anything file.
*
* @param parent the parent
* @param name the name
* @param path2 the name
*/
public CanBeAnythingFile(final String parent, final String name) {
this.parent = parent;
this.name = name;
public CanBeAnythingFile(final Path parent, final String name) {
this.path = parent.resolve(name);
}
/*
......@@ -50,7 +50,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/
@Override
public String getAbsolutePath() {
return parent.length() > 1 ? parent.concat("/").concat(name) : parent.concat(name);
return path.toAbsolutePath().toString();
}
/*
......@@ -59,7 +59,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/
@Override
public String getName() {
return name;
return path.getFileName().toString();
}
/*
......@@ -77,7 +77,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/
@Override
public boolean isDirectory() {
return true;
return dir;
}
/*
......@@ -86,7 +86,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/
@Override
public boolean isFile() {
return true;
return !dir;
}
/*
......@@ -158,7 +158,7 @@ public abstract class CanBeAnythingFile implements FtpFile {
*/
@Override
public long getLastModified() {
return 0;
return date;
}
/*
......
......@@ -301,9 +301,9 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
// directory
directory(path.toString(), this)
// or file
: file(repositoryService.getFile(
: file(FtpRunAs.asFtpUser(user, () -> repositoryService.getFile(
path.getParent().toString(),
path.getFileName().toString()), this);
path.getFileName().toString())), this);
} catch (final AuthenticationException e) {
LOG.warn("Authentication problem {}", e.getMessage(), e);
......@@ -311,10 +311,11 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
} catch (final NoSuchRepositoryFileException e) {
LOG.debug("Making new CanBeAnythingFile path={} name={}", path.getParent().toString(), path.getFileName().toString());
return new CanBeAnythingFile(path.getParent().toString(), path.getFileName().toString()) {
return new CanBeAnythingFile(path.getParent(), path.getFileName().toString()) {
@Override
public boolean mkdir() {
this.dir = true;
LOG.info("Mkdir path={}", this.getAbsolutePath());
temporaryDirs.add(this.getAbsolutePath());
return true;
......@@ -391,8 +392,8 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
* @param user the user
*/
public RepositoryFileSystemView(final FtpUser user) {
username = user.getName();
this.user = user;
username = user.getName();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment