Skip to content

An open-source cross-platform alternative to AirDrop

fix: read file metadata in nanosecs

Tien Do Namff2995c9523c
diff --git a/app/lib/model/cross_file.dart b/app/lib/model/cross_file.dart
index 47e47dc7..4680bf0c 100644
--- a/app/lib/model/cross_file.dart
+++ b/app/lib/model/cross_file.dart
@@ -17,8 +17,8 @@ class CrossFile with CrossFileMappable {
final AssetEntity? asset; // for thumbnails
final String? path;
final List<int>? bytes; // if type message, then UTF-8 encoded
- final DateTime? lastModified;
- final DateTime? lastAccessed;
+ final String? lastModified; // RFC 3339; a string because DateTime would truncate to microseconds
+ final String? lastAccessed; // RFC 3339
const CrossFile({
required this.name,
diff --git a/app/lib/model/cross_file.mapper.dart b/app/lib/model/cross_file.mapper.dart
index c612dbba..6938c9ec 100644
--- a/app/lib/model/cross_file.mapper.dart
+++ b/app/lib/model/cross_file.mapper.dart
@@ -43,13 +43,13 @@ class CrossFileMapper extends ClassMapperBase<CrossFile> {
static const Field<CrossFile, String> _f$path = Field('path', _$path);
static List<int>? _$bytes(CrossFile v) => v.bytes;
static const Field<CrossFile, List<int>> _f$bytes = Field('bytes', _$bytes);
- static DateTime? _$lastModified(CrossFile v) => v.lastModified;
- static const Field<CrossFile, DateTime> _f$lastModified = Field(
+ static String? _$lastModified(CrossFile v) => v.lastModified;
+ static const Field<CrossFile, String> _f$lastModified = Field(
'lastModified',
_$lastModified,
);
- static DateTime? _$lastAccessed(CrossFile v) => v.lastAccessed;
- static const Field<CrossFile, DateTime> _f$lastAccessed = Field(
+ static String? _$lastAccessed(CrossFile v) => v.lastAccessed;
+ static const Field<CrossFile, String> _f$lastAccessed = Field(
'lastAccessed',
_$lastAccessed,
);
@@ -149,8 +149,8 @@ abstract class CrossFileCopyWith<$R, $In extends CrossFile, $Out>
AssetEntity? asset,
String? path,
List<int>? bytes,
- DateTime? lastModified,
- DateTime? lastAccessed,
+ String? lastModified,
+ String? lastAccessed,
});
CrossFileCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}
diff --git a/app/lib/provider/network/webrtc/webrtc_receiver.dart b/app/lib/provider/network/webrtc/webrtc_receiver.dart
index 7b655f88..b58ba856 100644
--- a/app/lib/provider/network/webrtc/webrtc_receiver.dart
+++ b/app/lib/provider/network/webrtc/webrtc_receiver.dart
@@ -206,8 +206,8 @@ extension on FileDto {
extension on FileMetadata {
dart_model.FileMetadata toFileMetadata() {
return dart_model.FileMetadata(
- lastModified: DateTime.tryParse(modified ?? ''),
- lastAccessed: DateTime.tryParse(accessed ?? ''),
+ lastModified: modified,
+ lastAccessed: accessed,
);
}
}
diff --git a/app/lib/provider/selection/selected_sending_files_provider.dart b/app/lib/provider/selection/selected_sending_files_provider.dart
index acef6516..2ed37bca 100644
--- a/app/lib/provider/selection/selected_sending_files_provider.dart
+++ b/app/lib/provider/selection/selected_sending_files_provider.dart
@@ -8,6 +8,7 @@ import 'package:localsend_app/util/native/channel/android_channel.dart' as andro
import 'package:localsend_app/util/native/cross_file_converters.dart';
import 'package:localsend_app/util/send_ignore.dart';
import 'package:localsend_isolates/model/file_type.dart';
+import 'package:localsend_isolates/rust/api/metadata.dart';
import 'package:localsend_isolates/util/content_uri_helper.dart';
import 'package:localsend_isolates/util/file_path_helper.dart';
import 'package:logging/logging.dart';
@@ -175,6 +176,7 @@ class AddDirectoryAction extends AsyncReduxAction<SelectedSendingFilesNotifier,
_logger.info('Add file $relative');
+ final metadata = await readFileMetadata(path: entity.path);
final file = CrossFile(
name: relative,
fileType: relative.guessFileType(),
@@ -183,8 +185,8 @@ class AddDirectoryAction extends AsyncReduxAction<SelectedSendingFilesNotifier,
asset: null,
path: entity.path,
bytes: null,
- lastModified: entity.lastModifiedSync().toUtc(),
- lastAccessed: entity.lastAccessedSync().toUtc(),
+ lastModified: metadata?.modified,
+ lastAccessed: metadata?.accessed,
);
final isAlreadySelect = state.any((element) => element.isSameFile(otherFile: file));
@@ -244,7 +246,8 @@ class AddAndroidDirectoryAction extends AsyncReduxAction<SelectedSendingFilesNot
asset: null,
path: file.uri,
bytes: null,
- lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified, isUtc: true),
+ // SAF only provides milliseconds, so there is no point statting in Rust.
+ lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified, isUtc: true).toIso8601String(),
lastAccessed: null,
);
diff --git a/app/lib/util/native/cross_file_converters.dart b/app/lib/util/native/cross_file_converters.dart
index 8e6edd85..c9704107 100644
--- a/app/lib/util/native/cross_file_converters.dart
+++ b/app/lib/util/native/cross_file_converters.dart
@@ -6,6 +6,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:localsend_app/model/cross_file.dart';
import 'package:localsend_app/util/native/channel/android_channel.dart' as android_channel;
import 'package:localsend_isolates/model/file_type.dart';
+import 'package:localsend_isolates/rust/api/metadata.dart';
import 'package:localsend_isolates/util/file_path_helper.dart';
import 'package:share_handler/share_handler.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
@@ -14,6 +15,7 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
class CrossFileConverters {
static Future<CrossFile> convertAssetEntity(AssetEntity asset) async {
final file = (await asset.originFile)!;
+ final metadata = await readFileMetadata(path: file.path);
return CrossFile(
name: await asset.titleAsync,
fileType: asset.type == AssetType.video ? FileType.video : FileType.image,
@@ -22,12 +24,13 @@ class CrossFileConverters {
asset: asset,
path: file.path,
bytes: null,
- lastModified: file.lastModifiedSync().toUtc(),
- lastAccessed: file.lastAccessedSync().toUtc(),
+ lastModified: metadata?.modified,
+ lastAccessed: metadata?.accessed,
);
}
static Future<CrossFile> convertXFile(XFile file) async {
+ final metadata = kIsWeb ? null : await readFileMetadata(path: file.path);
return CrossFile(
name: file.name,
fileType: file.name.guessFileType(),
@@ -36,12 +39,13 @@ class CrossFileConverters {
asset: null,
path: kIsWeb ? null : file.path,
bytes: kIsWeb ? await file.readAsBytes() : null, // we can fetch it now because in Web it is already there
- lastModified: kIsWeb ? null : await file.lastModified(),
- lastAccessed: null,
+ lastModified: metadata?.modified,
+ lastAccessed: metadata?.accessed,
);
}
static Future<CrossFile> convertFile(File file) async {
+ final metadata = await readFileMetadata(path: file.path);
return CrossFile(
name: file.path.fileName,
fileType: file.path.fileName.guessFileType(),
@@ -50,8 +54,8 @@ class CrossFileConverters {
asset: null,
path: file.path,
bytes: null,
- lastModified: file.lastModifiedSync().toUtc(),
- lastAccessed: file.lastAccessedSync().toUtc(),
+ lastModified: metadata?.modified,
+ lastAccessed: metadata?.accessed,
);
}
@@ -64,7 +68,8 @@ class CrossFileConverters {
asset: null,
path: file.uri,
bytes: null,
- lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified, isUtc: true),
+ // SAF only provides milliseconds, so there is no point statting in Rust.
+ lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified, isUtc: true).toIso8601String(),
lastAccessed: null,
);
}
@@ -72,6 +77,7 @@ class CrossFileConverters {
static Future<CrossFile> convertSharedAttachment(SharedAttachment attachment) async {
final file = File(attachment.path);
final fileName = attachment.path.fileName;
+ final metadata = await readFileMetadata(path: file.path);
return CrossFile(
name: fileName,
fileType: fileName.guessFileType(),
@@ -80,8 +86,8 @@ class CrossFileConverters {
asset: null,
path: file.path,
bytes: null,
- lastModified: file.lastModifiedSync().toUtc(),
- lastAccessed: file.lastAccessedSync().toUtc(),
+ lastModified: metadata?.modified,
+ lastAccessed: metadata?.accessed,
);
}
diff --git a/cli/src/app/sending.rs b/cli/src/app/sending.rs
index 70546178..00622292 100644
--- a/cli/src/app/sending.rs
+++ b/cli/src/app/sending.rs
@@ -8,7 +8,7 @@ use crate::ui::Category;
use crate::util::SpeedMeter;
use crossterm::event::KeyEvent;
use localsend::discovery::StatefulDevice;
-use localsend::model::transfer::FileDto;
+use localsend::model::transfer::{FileDto, FileMetadata};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
@@ -162,7 +162,7 @@ impl App {
.to_string(),
sha256: None,
preview: None,
- metadata: None,
+ metadata: FileMetadata::from_fs_metadata(&metadata),
},
);
paths.insert(id, path);
diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml
index 3f270ca6..7a5c1fd1 100644
--- a/packages/core/Cargo.toml
+++ b/packages/core/Cargo.toml
@@ -28,7 +28,7 @@ serde_json = "1.0.151"
sha2 = { version = "0.11.0", optional = true }
socket2 = { version = "0.6.5", optional = true }
thiserror = "2.0.19"
-time = { version = "0.3.54", features = ["parsing"], optional = true }
+time = { version = "0.3.54", features = ["formatting", "parsing"], optional = true }
tokio = { version = "1.53.1", features = ["full"] }
tokio-rustls = { version = "0.26.4", default-features = false, features = ["ring", "tls12"], optional = true }
tokio-stream = "0.1.19"
diff --git a/packages/core/src/model/transfer.rs b/packages/core/src/model/transfer.rs
index 56078ecb..f5b441a7 100644
--- a/packages/core/src/model/transfer.rs
+++ b/packages/core/src/model/transfer.rs
@@ -124,6 +124,22 @@ pub struct FileMetadata {
#[cfg(feature = "http")]
impl FileMetadata {
+ /// The timestamps of the file at `path`, or `None` when the file cannot be
+ /// inspected or provides no timestamps.
+ pub fn from_path(path: &std::path::Path) -> Option<Self> {
+ Self::from_fs_metadata(&std::fs::metadata(path).ok()?)
+ }
+
+ /// See [`FileMetadata::from_path`], on an already obtained [`std::fs::Metadata`].
+ pub fn from_fs_metadata(metadata: &std::fs::Metadata) -> Option<Self> {
+ let modified = metadata.modified().ok().and_then(format_timestamp);
+ let accessed = metadata.accessed().ok().and_then(format_timestamp);
+ if modified.is_none() && accessed.is_none() {
+ return None;
+ }
+ Some(Self { modified, accessed })
+ }
+
/// The `modified` timestamp parsed as a [`std::time::SystemTime`],
/// or `None` when absent or not parsable.
pub fn modified_time(&self) -> Option<std::time::SystemTime> {
@@ -150,6 +166,18 @@ fn parse_timestamp(value: &str) -> Option<std::time::SystemTime> {
}
}
+/// Formats a timestamp as RFC 3339 with nanosecond precision.
+#[cfg(feature = "http")]
+fn format_timestamp(value: std::time::SystemTime) -> Option<String> {
+ match time::OffsetDateTime::from(value).format(&time::format_description::well_known::Rfc3339) {
+ Ok(formatted) => Some(formatted),
+ Err(e) => {
+ tracing::warn!("Could not format file timestamp: {e}");
+ None
+ }
+ }
+}
+
#[cfg(all(test, feature = "http"))]
mod tests {
use super::*;
@@ -194,6 +222,44 @@ mod tests {
assert_eq!(metadata("2000-01-01T00:00:00").modified_time(), None);
}
+ #[test]
+ fn formats_nanosecond_timestamp() {
+ let time = SystemTime::UNIX_EPOCH + Duration::from_nanos(123_456_789);
+ let formatted = format_timestamp(time).unwrap();
+ assert_eq!(formatted, "1970-01-01T00:00:00.123456789Z");
+ assert_eq!(parse_timestamp(&formatted), Some(time));
+ }
+
+ #[test]
+ fn reads_file_timestamps() {
+ let path =
+ std::env::temp_dir().join(format!("localsend-metadata-{}", uuid::Uuid::new_v4()));
+ std::fs::write(&path, b"hello").unwrap();
+ // 100 ns aligned, so the values are exactly representable on NTFS.
+ let modified = SystemTime::UNIX_EPOCH + Duration::new(1_600_000_000, 123_456_700);
+ let accessed = SystemTime::UNIX_EPOCH + Duration::new(1_600_000_001, 987_654_300);
+ let file = std::fs::File::options().write(true).open(&path).unwrap();
+ file.set_times(
+ std::fs::FileTimes::new()
+ .set_modified(modified)
+ .set_accessed(accessed),
+ )
+ .unwrap();
+ drop(file);
+
+ let metadata = FileMetadata::from_path(&path).unwrap();
+ std::fs::remove_file(&path).unwrap();
+ assert_eq!(metadata.modified_time(), Some(modified));
+ assert_eq!(metadata.accessed_time(), Some(accessed));
+ }
+
+ #[test]
+ fn reads_no_metadata_from_missing_file() {
+ assert!(
+ FileMetadata::from_path(std::path::Path::new("/nonexistent/localsend-test")).is_none()
+ );
+ }
+
#[test]
fn ignores_absent_timestamp() {
let metadata = FileMetadata {
diff --git a/packages/localsend_isolates/lib/model/dto/file_dto.dart b/packages/localsend_isolates/lib/model/dto/file_dto.dart
index d68f39c2..e3ba8e50 100644
--- a/packages/localsend_isolates/lib/model/dto/file_dto.dart
+++ b/packages/localsend_isolates/lib/model/dto/file_dto.dart
@@ -5,13 +5,15 @@ import 'package:mime/mime.dart';
part 'file_dto.mapper.dart';
+/// The timestamps are kept as raw RFC 3339 strings instead of [DateTime],
+/// which is capped at microseconds and would truncate nanosecond precision.
@MappableClass(ignoreNull: true)
class FileMetadata with FileMetadataMappable {
@MappableField(key: 'modified')
- final DateTime? lastModified;
+ final String? lastModified;
@MappableField(key: 'accessed')
- final DateTime? lastAccessed;
+ final String? lastAccessed;
const FileMetadata({
required this.lastModified,
diff --git a/packages/localsend_isolates/lib/model/dto/file_dto.mapper.dart b/packages/localsend_isolates/lib/model/dto/file_dto.mapper.dart
index 6e1ec0f0..84127b54 100644
--- a/packages/localsend_isolates/lib/model/dto/file_dto.mapper.dart
+++ b/packages/localsend_isolates/lib/model/dto/file_dto.mapper.dart
@@ -22,14 +22,14 @@ class FileMetadataMapper extends ClassMapperBase<FileMetadata> {
@override
final String id = 'FileMetadata';
- static DateTime? _$lastModified(FileMetadata v) => v.lastModified;
- static const Field<FileMetadata, DateTime> _f$lastModified = Field(
+ static String? _$lastModified(FileMetadata v) => v.lastModified;
+ static const Field<FileMetadata, String> _f$lastModified = Field(
'lastModified',
_$lastModified,
key: r'modified',
);
- static DateTime? _$lastAccessed(FileMetadata v) => v.lastAccessed;
- static const Field<FileMetadata, DateTime> _f$lastAccessed = Field(
+ static String? _$lastAccessed(FileMetadata v) => v.lastAccessed;
+ static const Field<FileMetadata, String> _f$lastAccessed = Field(
'lastAccessed',
_$lastAccessed,
key: r'accessed',
@@ -112,7 +112,7 @@ extension FileMetadataValueCopy<$R, $Out>
abstract class FileMetadataCopyWith<$R, $In extends FileMetadata, $Out>
implements ClassCopyWith<$R, $In, $Out> {
- $R call({DateTime? lastModified, DateTime? lastAccessed});
+ $R call({String? lastModified, String? lastAccessed});
FileMetadataCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}
diff --git a/packages/localsend_isolates/lib/rust/api/http.dart b/packages/localsend_isolates/lib/rust/api/http.dart
index ef91da4c..5d34c8d6 100644
--- a/packages/localsend_isolates/lib/rust/api/http.dart
+++ b/packages/localsend_isolates/lib/rust/api/http.dart
@@ -12,7 +12,7 @@ import 'package:localsend_isolates/rust/frb_generated.dart';
part 'http.freezed.dart';
-// These functions are ignored because they are not marked as `pub`: `error_chain`, `resolve_file_content`
+// These functions are ignored because they are not marked as `pub`: `resolve_file_content`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `from`
/// Creates an HTTP client.
diff --git a/packages/localsend_isolates/lib/rust/api/metadata.dart b/packages/localsend_isolates/lib/rust/api/metadata.dart
new file mode 100644
index 00000000..6c186a25
--- /dev/null
+++ b/packages/localsend_isolates/lib/rust/api/metadata.dart
@@ -0,0 +1,13 @@
+// This file is automatically generated, so please do not edit it.
+// @generated by `flutter_rust_bridge`@ 2.12.0.
+
+// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
+
+import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
+import 'package:localsend_isolates/rust/api/model.dart';
+import 'package:localsend_isolates/rust/frb_generated.dart';
+
+/// Reads the timestamps of the file at `path` in the protocol's RFC 3339
+/// format with nanosecond precision, which Dart's `DateTime` cannot express.
+/// `None` when the file cannot be inspected or provides no timestamps.
+Future<FileMetadata?> readFileMetadata({required String path}) => RustLib.instance.api.crateApiMetadataReadFileMetadata(path: path);
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.dart b/packages/localsend_isolates/lib/rust/frb_generated.dart
index 2bc25d32..6445080c 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.dart
@@ -13,6 +13,7 @@ import 'package:localsend_isolates/rust/api/discovery.dart';
import 'package:localsend_isolates/rust/api/filename.dart';
import 'package:localsend_isolates/rust/api/http.dart';
import 'package:localsend_isolates/rust/api/logging.dart';
+import 'package:localsend_isolates/rust/api/metadata.dart';
import 'package:localsend_isolates/rust/api/model.dart';
import 'package:localsend_isolates/rust/api/server.dart';
import 'package:localsend_isolates/rust/api/stream.dart';
@@ -75,7 +76,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.12.0';
@override
- int get rustContentHash => -2095161624;
+ int get rustContentHash => -324914520;
static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig(
stem: 'rust_lib_localsend_app',
@@ -276,6 +277,8 @@ abstract class RustLibApi extends BaseApi {
bool crateApiFilenameIsValidFileName({required String name});
+ Future<FileMetadata?> crateApiMetadataReadFileMetadata({required String path});
+
String crateApiFilenameSanitizeFileName({required String name});
Future<RsDiscovery> crateApiDiscoveryStartDiscovery({
@@ -1954,6 +1957,31 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ['name'],
);
+ @override
+ Future<FileMetadata?> crateApiMetadataReadFileMetadata({required String path}) {
+ return handler.executeNormal(
+ NormalTask(
+ callFfi: (port_) {
+ final serializer = SseSerializer(generalizedFrbRustBinding);
+ sse_encode_String(path, serializer);
+ pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 54, port: port_);
+ },
+ codec: SseCodec(
+ decodeSuccessData: sse_decode_opt_box_autoadd_file_metadata,
+ decodeErrorData: null,
+ ),
+ constMeta: kCrateApiMetadataReadFileMetadataConstMeta,
+ argValues: [path],
+ apiImpl: this,
+ ),
+ );
+ }
+
+ TaskConstMeta get kCrateApiMetadataReadFileMetadataConstMeta => const TaskConstMeta(
+ debugName: 'read_file_metadata',
+ argNames: ['path'],
+ );
+
@override
String crateApiFilenameSanitizeFileName({required String name}) {
return handler.executeSync(
@@ -1961,7 +1989,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: () {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(name, serializer);
- return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 54)!;
+ return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 55)!;
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
@@ -2014,7 +2042,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(certPem, serializer);
sse_encode_String(privateKeyPem, serializer);
sse_encode_u_64(timeoutMs, serializer);
- pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 55, port: port_);
+ pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 56, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerRsDiscovery,
@@ -2091,7 +2119,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_bool(verifyChecksums, serializer);
sse_encode_opt_box_autoadd_web_params(web, serializer);
sse_encode_opt_String(showToken, serializer);
- pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 56, port: port_);
+ pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 57, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerRsHttpServer,
@@ -2117,7 +2145,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(cert, serializer);
sse_encode_String(publicKey, serializer);
- pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 57, port: port_);
+ pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 58, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.io.dart b/packages/localsend_isolates/lib/rust/frb_generated.io.dart
index 08b4d37b..5e2773fa 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.io.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.io.dart
@@ -14,6 +14,7 @@ import 'package:localsend_isolates/rust/api/discovery.dart';
import 'package:localsend_isolates/rust/api/filename.dart';
import 'package:localsend_isolates/rust/api/http.dart';
import 'package:localsend_isolates/rust/api/logging.dart';
+import 'package:localsend_isolates/rust/api/metadata.dart';
import 'package:localsend_isolates/rust/api/model.dart';
import 'package:localsend_isolates/rust/api/server.dart';
import 'package:localsend_isolates/rust/api/stream.dart';
diff --git a/packages/localsend_isolates/lib/rust/frb_generated.web.dart b/packages/localsend_isolates/lib/rust/frb_generated.web.dart
index 9a7c8ee7..704605dc 100644
--- a/packages/localsend_isolates/lib/rust/frb_generated.web.dart
+++ b/packages/localsend_isolates/lib/rust/frb_generated.web.dart
@@ -16,6 +16,7 @@ import 'package:localsend_isolates/rust/api/discovery.dart';
import 'package:localsend_isolates/rust/api/filename.dart';
import 'package:localsend_isolates/rust/api/http.dart';
import 'package:localsend_isolates/rust/api/logging.dart';
+import 'package:localsend_isolates/rust/api/metadata.dart';
import 'package:localsend_isolates/rust/api/model.dart';
import 'package:localsend_isolates/rust/api/server.dart';
import 'package:localsend_isolates/rust/api/stream.dart';
diff --git a/packages/localsend_isolates/lib/util/rust.dart b/packages/localsend_isolates/lib/util/rust.dart
index 359a31d6..06dfb991 100644
--- a/packages/localsend_isolates/lib/util/rust.dart
+++ b/packages/localsend_isolates/lib/util/rust.dart
@@ -64,8 +64,8 @@ extension FileDtoExt on FileDto {
preview: preview,
metadata: metadata != null
? rust_model.FileMetadata(
- modified: metadata!.lastModified?.toUtc().toIso8601String(),
- accessed: metadata!.lastAccessed?.toUtc().toIso8601String(),
+ modified: metadata!.lastModified,
+ accessed: metadata!.lastAccessed,
)
: null,
);
@@ -123,8 +123,8 @@ extension RustFileDtoExt on rust_model.FileDto {
preview: preview,
metadata: metadata != null
? FileMetadata(
- lastModified: metadata!.modified != null ? DateTime.tryParse(metadata!.modified!) : null,
- lastAccessed: metadata!.accessed != null ? DateTime.tryParse(metadata!.accessed!) : null,
+ lastModified: metadata!.modified,
+ lastAccessed: metadata!.accessed,
)
: null,
);
diff --git a/packages/localsend_isolates/rust/src/api/metadata.rs b/packages/localsend_isolates/rust/src/api/metadata.rs
new file mode 100644
index 00000000..519d7acd
--- /dev/null
+++ b/packages/localsend_isolates/rust/src/api/metadata.rs
@@ -0,0 +1,8 @@
+use localsend::model::transfer::FileMetadata;
+
+/// Reads the timestamps of the file at `path` in the protocol's RFC 3339
+/// format with nanosecond precision, which Dart's `DateTime` cannot express.
+/// `None` when the file cannot be inspected or provides no timestamps.
+pub async fn read_file_metadata(path: String) -> Option<FileMetadata> {
+ FileMetadata::from_path(std::path::Path::new(&path))
+}
diff --git a/packages/localsend_isolates/rust/src/api/mod.rs b/packages/localsend_isolates/rust/src/api/mod.rs
index d6f3549b..abd8804d 100644
--- a/packages/localsend_isolates/rust/src/api/mod.rs
+++ b/packages/localsend_isolates/rust/src/api/mod.rs
@@ -4,6 +4,7 @@ pub mod discovery;
pub mod filename;
pub mod http;
pub mod logging;
+pub mod metadata;
pub mod model;
pub mod server;
pub mod stream;
diff --git a/packages/localsend_isolates/rust/src/frb_generated.rs b/packages/localsend_isolates/rust/src/frb_generated.rs
index 33e949da..4f5cf155 100644
--- a/packages/localsend_isolates/rust/src/frb_generated.rs
+++ b/packages/localsend_isolates/rust/src/frb_generated.rs
@@ -44,7 +44,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueMoi,
);
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.12.0";
-pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -2095161624;
+pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -324914520;
// Section: executor
@@ -3133,6 +3133,44 @@ fn wire__crate__api__filename__is_valid_file_name_impl(
},
)
}
+fn wire__crate__api__metadata__read_file_metadata_impl(
+ port_: flutter_rust_bridge::for_generated::MessagePort,
+ ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
+ rust_vec_len_: i32,
+ data_len_: i32,
+) {
+ FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::SseCodec, _, _, _>(
+ flutter_rust_bridge::for_generated::TaskInfo {
+ debug_name: "read_file_metadata",
+ port: Some(port_),
+ mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
+ },
+ move || {
+ let message = unsafe {
+ flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
+ ptr_,
+ rust_vec_len_,
+ data_len_,
+ )
+ };
+ let mut deserializer =
+ flutter_rust_bridge::for_generated::SseDeserializer::new(message);
+ let api_path = <String>::sse_decode(&mut deserializer);
+ deserializer.end();
+ move |context| async move {
+ transform_result_sse::<_, ()>(
+ (move || async move {
+ let output_ok = Result::<_, ()>::Ok(
+ crate::api::metadata::read_file_metadata(api_path).await,
+ )?;
+ Ok(output_ok)
+ })()
+ .await,
+ )
+ }
+ },
+ )
+}
fn wire__crate__api__filename__sanitize_file_name_impl(
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
@@ -5313,9 +5351,12 @@ fn pde_ffi_dispatcher_primary_impl(
data_len,
),
52 => wire__crate__api__crypto__hash_file_impl(port, ptr, rust_vec_len, data_len),
- 55 => wire__crate__api__discovery__start_discovery_impl(port, ptr, rust_vec_len, data_len),
- 56 => wire__crate__api__server__start_server_impl(port, ptr, rust_vec_len, data_len),
- 57 => wire__crate__api__crypto__verify_cert_impl(port, ptr, rust_vec_len, data_len),
+ 54 => {
+ wire__crate__api__metadata__read_file_metadata_impl(port, ptr, rust_vec_len, data_len)
+ }
+ 56 => wire__crate__api__discovery__start_discovery_impl(port, ptr, rust_vec_len, data_len),
+ 57 => wire__crate__api__server__start_server_impl(port, ptr, rust_vec_len, data_len),
+ 58 => wire__crate__api__crypto__verify_cert_impl(port, ptr, rust_vec_len, data_len),
_ => unreachable!(),
}
}
@@ -5333,7 +5374,7 @@ fn pde_ffi_dispatcher_sync_impl(
46 => wire__crate__api__cancel__create_cancellation_token_impl(ptr, rust_vec_len, data_len),
47 => wire__crate__api__http__create_client_impl(ptr, rust_vec_len, data_len),
53 => wire__crate__api__filename__is_valid_file_name_impl(ptr, rust_vec_len, data_len),
- 54 => wire__crate__api__filename__sanitize_file_name_impl(ptr, rust_vec_len, data_len),
+ 55 => wire__crate__api__filename__sanitize_file_name_impl(ptr, rust_vec_len, data_len),
_ => unreachable!(),
}
}