Skip to content

Commit

Permalink
fixed warnings, see GH wolpi#395
Browse files Browse the repository at this point in the history
  • Loading branch information
wolpi authored and lmagyar committed Oct 6, 2024
1 parent 0e7f073 commit a9ce7a7
Show file tree
Hide file tree
Showing 40 changed files with 273 additions and 350 deletions.
12 changes: 6 additions & 6 deletions primitiveFTPd/src/org/primftpd/filesystem/AbstractFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class AbstractFile<TFileSystemView extends AbstractFileSystemVie

protected final Logger logger = LoggerFactory.getLogger(getClass());

private final AbstractFileSystemView fileSystemView;
private final TFileSystemView fileSystemView;

protected String absPath;
protected String name;
Expand All @@ -31,7 +31,7 @@ public AbstractFile(
}

protected final TFileSystemView getFileSystemView() {
return (TFileSystemView)fileSystemView;
return fileSystemView;
}

protected final PftpdService getPftpdService() {
Expand Down Expand Up @@ -90,7 +90,7 @@ public String getName() {

public abstract boolean delete();

public abstract boolean move(AbstractFile destination);
public abstract boolean move(AbstractFile<TFileSystemView> destination);

public abstract OutputStream createOutputStream(long offset) throws IOException;

Expand Down Expand Up @@ -125,7 +125,7 @@ public void handleClose() throws IOException {
logger.trace("[{}] handleClose()", name);
}

public void truncate() throws IOException {
public void truncate() {
// TODO ssh truncate
logger.trace("[{}] truncate()", name);
}
Expand All @@ -145,7 +145,7 @@ public void createSymbolicLink(SshFile arg0)
logger.trace("[{}] createSymbolicLink()", name);
}

public void setAttribute(SshFile.Attribute attribute, Object value) throws IOException {
public void setAttribute(SshFile.Attribute attribute, Object value) {
logger.trace("[{}] setAttribute({})", name, attribute);
SshUtils.setAttribute((SshFile)this, attribute, value);
}
Expand All @@ -161,7 +161,7 @@ public Object getAttribute(SshFile.Attribute attribute, boolean followLinks)
throws IOException
{
logger.trace("[{}] getAttribute({})", name, attribute);
return SshUtils.getAttribute((SshFile)this, attribute, followLinks);
return SshUtils.getAttribute((SshFile)this, attribute);
}

public Map<SshFile.Attribute, Object> getAttributes(boolean followLinks)
Expand Down
45 changes: 25 additions & 20 deletions primitiveFTPd/src/org/primftpd/filesystem/FsFile.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.primftpd.filesystem;

import org.primftpd.events.ClientActionEvent;
import org.primftpd.services.PftpdService;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
Expand All @@ -20,7 +19,8 @@
import java.util.Map;
import java.util.Set;

public abstract class FsFile<TMina, TFileSystemView extends FsFileSystemView> extends AbstractFile<TFileSystemView> {
public abstract class FsFile<TMina, TFileSystemView extends FsFileSystemView>
extends AbstractFile<TFileSystemView> {

protected final File file;
protected final boolean isInjectedDirectory;
Expand Down Expand Up @@ -81,7 +81,7 @@ public boolean doesExist() {
// exists may be false when we don't have read permission
// try to figure out if it really does not exist
File parentFile = file.getParentFile();
File[] children = parentFile.listFiles();
File[] children = parentFile != null ? parentFile.listFiles() : new File[]{};
if (children != null) {
for (File child : children) {
if (file.equals(child)) {
Expand All @@ -96,8 +96,8 @@ public boolean doesExist() {
new Object[]{
name,
file.getAbsolutePath(),
Boolean.valueOf(exists),
Boolean.valueOf(existsChecked)
exists,
existsChecked
});
return existsChecked;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public boolean isRemovable() {
}

public boolean setLastModified(long time) {
logger.trace("[{}] setLastModified({})", name, Long.valueOf(time));
logger.trace("[{}] setLastModified({})", name, time);
long correctedTime = getFileSystemView().getCorrectedTime(file.getAbsolutePath(), time);
return file.setLastModified(correctedTime);
}
Expand All @@ -183,7 +183,7 @@ public boolean delete() {
return success;
}

public boolean move(AbstractFile destination) {
public boolean move(AbstractFile<TFileSystemView> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
postClientAction(ClientActionEvent.ClientAction.RENAME);
boolean success = file.renameTo(new File(destination.getAbsolutePath()));
Expand Down Expand Up @@ -232,31 +232,36 @@ public OutputStream createOutputStream(long offset) throws IOException {
// some clients do not issue mkdir commands like filezilla
// see isWritable()
File parent = file.getParentFile();
if (parent == null) {
throw new IOException(String.format("Failed to create parent folder(s) '%s'", file.getAbsolutePath()));
}
if (!parent.exists()) {
if (!parent.mkdirs()) {
throw new IOException(String.format("Failed to create parent folder(s) '%s'", file.getAbsolutePath()));
}
}

// now create out stream
OutputStream os = null;
OutputStream os;
if (offset == 0) {
os = new FileOutputStream(file);
} else if (offset == this.file.length()) {
os = new FileOutputStream(file, true);
} else {
final RandomAccessFile raf = new RandomAccessFile(this.file, "rw");
raf.seek(offset);
os = new OutputStream() {
@Override
public void write(int oneByte) throws IOException {
raf.write(oneByte);
}
@Override
public void close() throws IOException {
raf.close();
}
};
try (final RandomAccessFile raf = new RandomAccessFile(this.file, "rw")) {
raf.seek(offset);
os = new OutputStream() {
@Override
public void write(int oneByte) throws IOException {
raf.write(oneByte);
}

@Override
public void close() throws IOException {
raf.close();
}
};
}
}

return new BufferedOutputStream(os) {
Expand Down
15 changes: 7 additions & 8 deletions primitiveFTPd/src/org/primftpd/filesystem/FsFileSystemView.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.primftpd.filesystem;

import android.content.Context;
import android.net.Uri;

import org.primftpd.services.PftpdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import org.primftpd.services.PftpdService;

public abstract class FsFileSystemView<TFile extends FsFile<TMina, ? extends FsFileSystemView>, TMina> extends AbstractFileSystemView {
public abstract class FsFileSystemView<
TFile extends FsFile<TMina, ? extends FsFileSystemView>, TMina>
extends AbstractFileSystemView {

private final MediaScannerClient mediaScannerClient;
private final String safVolumePath;
Expand All @@ -25,7 +22,9 @@ public FsFileSystemView(PftpdService pftpdService, Uri safStartUrl) {
// FS should not have some relation to SAF
// But to workaround Amdroid issues with lastModifiedTimestamps it is required anyway
this.safTimeResolution = StorageManagerUtil.getFilesystemTimeResolutionForTreeUri(safStartUrl);
this.safVolumePath = safTimeResolution != 1 ? StorageManagerUtil.getVolumePathFromTreeUri(safStartUrl, pftpdService.getContext()) : null;
this.safVolumePath = safTimeResolution != 1
? StorageManagerUtil.getVolumePathFromTreeUri(safStartUrl, pftpdService.getContext())
: null;
}

public final MediaScannerClient getMediaScannerClient() {
Expand Down
10 changes: 4 additions & 6 deletions primitiveFTPd/src/org/primftpd/filesystem/FsFtpFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.User;
import org.primftpd.services.PftpdService;

public class FsFtpFile extends FsFile<FtpFile, FsFtpFileSystemView> implements FtpFile {
private final User user;
Expand All @@ -26,7 +25,7 @@ protected FtpFile createFile(File file) {

@Override
public boolean move(FtpFile target) {
return super.move((AbstractFile) target);
return super.move((FsFtpFile) target);
}

@Override
Expand All @@ -49,9 +48,8 @@ public Object getPhysicalFile() {

@Override
public boolean isHidden() {
//boolean result = file.isHidden();
//logger.trace("[{}] isHidden() -> {}", name, result);
//return result;
return super.isHidden();
boolean result = file.isHidden();
logger.trace("[{}] isHidden() -> {}", name, result);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.primftpd.filesystem;

import android.content.Context;
import android.net.Uri;

import java.io.File;

import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.FileSystemView;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.User;
import org.primftpd.services.PftpdService;

import java.io.File;

public class FsFtpFileSystemView extends FsFileSystemView<FsFtpFile, FtpFile> implements FileSystemView {

private final File homeDir;
Expand Down Expand Up @@ -107,7 +105,7 @@ public boolean changeWorkingDirectory(String dir) {
return true;
}

public boolean isRandomAccessible() throws FtpException {
public boolean isRandomAccessible() {
logger.trace("isRandomAccessible()");

return true;
Expand Down
3 changes: 1 addition & 2 deletions primitiveFTPd/src/org/primftpd/filesystem/FsSshFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.sshd.common.Session;
import org.apache.sshd.common.file.SshFile;
import org.primftpd.services.PftpdService;

import java.io.File;
import java.io.IOException;
Expand All @@ -28,7 +27,7 @@ protected SshFile createFile(File file) {

@Override
public boolean move(SshFile target) {
return super.move((AbstractFile)target);
return super.move((FsSshFile)target);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.primftpd.filesystem;

import android.content.Context;
import android.net.Uri;

import java.io.File;

import org.apache.sshd.common.file.SshFile;
import org.apache.sshd.common.Session;
import org.apache.sshd.common.file.FileSystemView;
import org.apache.sshd.common.file.SshFile;
import org.primftpd.services.PftpdService;

import java.io.File;

public class FsSshFileSystemView extends FsFileSystemView<FsSshFile, SshFile> implements FileSystemView {

private final File homeDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public void scanFile(String path) {
// Android 10 (API level 29) and lower: just requests the scan
connection.scanFile(path, null);
} catch (Exception e) {
logger.error(" media scanning start error '{}' for file '{}'", e.toString(), path);
logger.error(" media scanning start error for file '{}': '{}' ", e, path);
}
}

@Override
public void onScanCompleted(String path, Uri uri) {
logger.info("media scanning completed for file '{}'", path);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.primftpd.filesystem;

import org.primftpd.events.ClientActionEvent;
import org.primftpd.services.PftpdService;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -108,7 +106,7 @@ public boolean delete() {
return false;
}

public boolean move(AbstractFile destination) {
public boolean move(AbstractFile<TFileSystemView> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.primftpd.filesystem;

import org.primftpd.services.PftpdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.User;
import org.primftpd.services.PftpdService;

import java.io.File;

Expand Down Expand Up @@ -36,7 +35,7 @@ protected FtpFile createFile(File realFile) {

@Override
public boolean move(FtpFile target) {
return super.move((AbstractFile) target);
return super.move((QuickShareFtpFile) target);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.sshd.common.Session;
import org.apache.sshd.common.file.SshFile;
import org.primftpd.services.PftpdService;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -37,7 +36,7 @@ public String getClientIp() {

@Override
public boolean move(SshFile target) {
return super.move((AbstractFile) target);
return super.move((QuickShareSshFile) target);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions primitiveFTPd/src/org/primftpd/filesystem/RoSafFile.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.primftpd.filesystem;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;

import org.primftpd.events.ClientActionEvent;
import org.primftpd.services.PftpdService;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -243,7 +241,7 @@ public boolean delete() {
return false;
}

public boolean move(AbstractFile destination) {
public boolean move(AbstractFile<TFileSystemView> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
// TODO writing with SAF cursor/uri api
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Loading

0 comments on commit a9ce7a7

Please sign in to comment.