Skip to content

Commit

Permalink
fix time resolution in roSAF
Browse files Browse the repository at this point in the history
  • Loading branch information
lmagyar committed Sep 26, 2024
1 parent 655364b commit 2d5be72
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
15 changes: 11 additions & 4 deletions primitiveFTPd/src/org/primftpd/filesystem/RoSafFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class RoSafFile<T> extends AbstractFile {

private final ContentResolver contentResolver;
protected final Uri startUrl;
protected final int timeResolution;

private String documentId;
private boolean writable;
Expand All @@ -40,7 +41,8 @@ public RoSafFile(
ContentResolver contentResolver,
Uri startUrl,
String absPath,
PftpdService pftpdService) {
PftpdService pftpdService,
int timeResolution) {
// this c-tor is to be used for start directory
super(
absPath,
Expand All @@ -54,6 +56,7 @@ public RoSafFile(
logger.trace(" c-tor 1");
this.contentResolver = contentResolver;
this.startUrl = startUrl;
this.timeResolution = timeResolution;

try {
Cursor cursor = contentResolver.query(
Expand Down Expand Up @@ -85,7 +88,8 @@ public RoSafFile(
String docId,
String absPath,
boolean exists,
PftpdService pftpdService) {
PftpdService pftpdService,
int timeResolution) {
// this c-tor is to be used for FileSystemView.getFile()
super(
absPath,
Expand All @@ -99,6 +103,7 @@ public RoSafFile(
logger.trace(" c-tor 2");
this.contentResolver = contentResolver;
this.startUrl = startUrl;
this.timeResolution = timeResolution;

if (exists) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -130,7 +135,8 @@ public RoSafFile(
Uri startUrl,
Cursor cursor,
String absPath,
PftpdService pftpdService) {
PftpdService pftpdService,
int timeResolution) {
// this c-tor is to be used by listFiles()
super(
absPath,
Expand All @@ -144,13 +150,14 @@ public RoSafFile(
logger.trace(" c-tor 3");
this.contentResolver = contentResolver;
this.startUrl = startUrl;
this.timeResolution = timeResolution;
initByCursor(cursor);
}

private void initByCursor(Cursor cursor) {
documentId = cursor.getString(0);
name = cursor.getString(1);
lastModified = cursor.getLong(2);
lastModified = (cursor.getLong(2) / timeResolution) * timeResolution;
size = cursor.getLong(3);

logger.trace(" initByCursor, doc id: {}, name: {}", documentId, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public abstract class RoSafFileSystemView<T extends RoSafFile<X>, X> {
protected final Uri startUrl;
protected final ContentResolver contentResolver;
protected final PftpdService pftpdService;
protected final int timeResolution;

public RoSafFileSystemView(Uri startUrl, ContentResolver contentResolver, PftpdService pftpdService) {
this.startUrl = startUrl;
this.contentResolver = contentResolver;
this.pftpdService = pftpdService;
this.timeResolution = StorageManagerUtil.getFilesystemTimeResolutionForTreeUri(startUrl);
}

protected abstract String absolute(String file);
Expand Down
11 changes: 7 additions & 4 deletions primitiveFTPd/src/org/primftpd/filesystem/RoSafFtpFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public RoSafFtpFile(
Uri startUrl,
String absPath,
PftpdService pftpdService,
int timeResolution,
User user) {
super(contentResolver, startUrl, absPath, pftpdService);
super(contentResolver, startUrl, absPath, pftpdService, timeResolution);
this.user = user;
}

Expand All @@ -29,8 +30,9 @@ public RoSafFtpFile(
String absPath,
boolean exists,
PftpdService pftpdService,
int timeResolution,
User user) {
super(contentResolver, startUrl, docId, absPath, exists, pftpdService);
super(contentResolver, startUrl, docId, absPath, exists, pftpdService, timeResolution);
this.user = user;
}

Expand All @@ -40,8 +42,9 @@ public RoSafFtpFile(
Cursor cursor,
String absPath,
PftpdService pftpdService,
int timeResolution,
User user) {
super(contentResolver, startUrl, cursor, absPath, pftpdService);
super(contentResolver, startUrl, cursor, absPath, pftpdService, timeResolution);
this.user = user;
}

Expand All @@ -52,7 +55,7 @@ protected FtpFile createFile(
Cursor cursor,
String absPath,
PftpdService pftpdService) {
return new RoSafFtpFile(contentResolver, startUrl, cursor, absPath, pftpdService, user);
return new RoSafFtpFile(contentResolver, startUrl, cursor, absPath, pftpdService, timeResolution, user);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public RoSafFtpFileSystemView(Uri startUrl, ContentResolver contentResolver, Pft

@Override
protected RoSafFtpFile createFile(ContentResolver contentResolver, Uri startUrl, String absPath, PftpdService pftpdService) {
return new RoSafFtpFile(contentResolver, startUrl, absPath, pftpdService, user);
return new RoSafFtpFile(contentResolver, startUrl, absPath, pftpdService, timeResolution, user);
}

@Override
protected RoSafFtpFile createFile(ContentResolver contentResolver, Uri startUrl, String docId, String absPath, PftpdService pftpdService) {
return new RoSafFtpFile(contentResolver, startUrl, docId, absPath, true, pftpdService, user);
return new RoSafFtpFile(contentResolver, startUrl, docId, absPath, true, pftpdService, timeResolution, user);
}

@Override
protected RoSafFtpFile createFileNonExistant(ContentResolver contentResolver, Uri startUrl, String name, String absPath, PftpdService pftpdService) {
return new RoSafFtpFile(contentResolver, startUrl, name, absPath, false, pftpdService, user);
return new RoSafFtpFile(contentResolver, startUrl, name, absPath, false, pftpdService, timeResolution, user);
}

@Override
Expand Down
11 changes: 7 additions & 4 deletions primitiveFTPd/src/org/primftpd/filesystem/RoSafSshFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public RoSafSshFile(
Uri startUrl,
String absPath,
PftpdService pftpdService,
int timeResolution,
Session session) {
super(contentResolver, startUrl, absPath, pftpdService);
super(contentResolver, startUrl, absPath, pftpdService, timeResolution);
this.session = session;
}

Expand All @@ -31,8 +32,9 @@ public RoSafSshFile(
String absPath,
boolean exists,
PftpdService pftpdService,
int timeResolution,
Session session) {
super(contentResolver, startUrl, docId, absPath, exists, pftpdService);
super(contentResolver, startUrl, docId, absPath, exists, pftpdService, timeResolution);
this.session = session;
}

Expand All @@ -42,8 +44,9 @@ public RoSafSshFile(
Cursor cursor,
String absPath,
PftpdService pftpdService,
int timeResolution,
Session session) {
super(contentResolver, startUrl, cursor, absPath, pftpdService);
super(contentResolver, startUrl, cursor, absPath, pftpdService, timeResolution);
this.session = session;
}

Expand All @@ -54,7 +57,7 @@ protected SshFile createFile(
Cursor cursor,
String absPath,
PftpdService pftpdService) {
return new RoSafSshFile(contentResolver, startUrl, cursor, absPath, pftpdService, session);
return new RoSafSshFile(contentResolver, startUrl, cursor, absPath, pftpdService, timeResolution, session);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public RoSafSshFileSystemView(Uri startUrl, ContentResolver contentResolver, Pft

@Override
protected RoSafSshFile createFile(ContentResolver contentResolver, Uri startUrl, String absPath, PftpdService pftpdService) {
return new RoSafSshFile(contentResolver, startUrl, absPath, pftpdService, session);
return new RoSafSshFile(contentResolver, startUrl, absPath, pftpdService, timeResolution, session);
}

@Override
protected RoSafSshFile createFile(ContentResolver contentResolver, Uri startUrl, String docId, String absPath, PftpdService pftpdService) {
return new RoSafSshFile(contentResolver, startUrl, docId, absPath, true, pftpdService, session);
return new RoSafSshFile(contentResolver, startUrl, docId, absPath, true, pftpdService, timeResolution, session);
}

@Override
protected RoSafSshFile createFileNonExistant(ContentResolver contentResolver, Uri startUrl, String name, String absPath, PftpdService pftpdService) {
return new RoSafSshFile(contentResolver, startUrl, name, absPath, false, pftpdService, session);
return new RoSafSshFile(contentResolver, startUrl, name, absPath, false, pftpdService, timeResolution, session);
}

@Override
Expand Down

0 comments on commit 2d5be72

Please sign in to comment.