Description
Describe the bug
If I'm not mistaken, DateModified should report the date and time of last write to the file or folder.
I noted that DateModified is returning LastAccessTime:
(Avalonia/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageItem.cs)
internal static StorageItemProperties GetBasicPropertiesAsyncCore(FileSystemInfo fileSystemInfo)
{
if (fileSystemInfo.Exists)
{
return new StorageItemProperties(
fileSystemInfo is FileInfo fileInfo ? (ulong)fileInfo.Length : 0,
fileSystemInfo.CreationTimeUtc,
fileSystemInfo. ***LastAccessTimeUtc*** ); // <<<<<<<<<<<<<<<<<< maybe is LastWriteTimeUtc???
}
return new StorageItemProperties();
}
To Reproduce
-
Pick an old file (for example, from your download folder) and copy it into your Documents folder.
-
Check the property of the file copied into the Documents folder. You'll probably see the dates like this:
Created ... now
Modified ... an old date (the same date of the original old file you copied from)
Accessed ... now
Note that just the Modified date is "old", and others two dates has been updated by the copy action.
- Check the date reported by DateModified using for example a fragment shown below:
TestCommand = ReactiveCommand.Create(async () =>
{
var file = await storageProvider.TryGetFileFromPathAsync(new Uri("file:///C:/Users/XXXXXX/Documents/test.txt"));
if (file is null)
{
Debug.WriteLine("File is null");
return;
}
var basicProperties = await file.GetBasicPropertiesAsync();
var datetimeoffset = basicProperties.DateModified;
if (datetimeoffset is { } datetime) Debug.WriteLine(datetime.ToLocalTime());
});
Note that it reports ACCESSED date, and maybe the correct is to report the MODIFIED (old) date.
Properties of the file copied into the Documents folder, Created, Modified and Accessed dates are shown;
Screenshot of debug console: The result from DateModified shows even more advanced time than reported in the screenshot above, maybe because just the TryGetFileFromPathAsync is updating the Accessed timestamp (???)
Expected behavior
I think it is better to DateModified report "FileSystemInfo.LastWriteTime" unless any specific reason (compatibility with other OS as MacOS, Linux, Android etc) make it hard to implement ...
Avalonia version
11.2.5
OS
Windows
Additional context
I am sorry but I did not check the influence of this issue on Linux / Mac machines...