Skip to content

Commit 442157b

Browse files
committed
Modified timestamp support
1 parent aa19c45 commit 442157b

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_FileWorkspaceMap.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.io.InputStream;
1515
import java.io.OutputStream;
16+
import java.sql.Date;
1617

1718
// JavaCommons imports
1819
import picoded.core.common.EmptyArray;
@@ -528,7 +529,9 @@ public void backend_ensureFolderPath(final String oid, final String folderPath)
528529
* @return DataObject created timestamp in ms
529530
*/
530531
public long backend_createdTimestamp(final String oid, final String filepath) {
531-
return -1;
532+
533+
// Currently only modified timestamp is supported
534+
return backend_modifiedTimestamp(oid, filepath);
532535
}
533536

534537
/**
@@ -543,6 +546,22 @@ public long backend_createdTimestamp(final String oid, final String filepath) {
543546
* @return DataObject created timestamp in ms
544547
*/
545548
public long backend_modifiedTimestamp(final String oid, final String filepath) {
549+
// Lets build the query for the "root file"
550+
Bson query = Filters.eq("filename", fullpath);
551+
552+
// Lets prepare the search
553+
GridFSFindIterable search = gridFSBucket.find(query).limit(1);
554+
555+
// Lets iterate the search result, and return true on an item
556+
try (MongoCursor<GridFSFile> cursor = search.iterator()) {
557+
if (cursor.hasNext()) {
558+
GridFSFile fileObj = cursor.next();
559+
Date uploadDate = fileObj.getUploadDate();
560+
return uploadDate.getTime();
561+
}
562+
}
563+
564+
// Fail, as the search found no iterations
546565
return -1;
547566
}
548567

0 commit comments

Comments
 (0)