* FileSystem.Unix: Directory.Delete: remove per item syscall.
By recursing using FileSystemEnumerable we know the file type and
can omit the stat calls made by DirectoryInfo.Exists.
For the top level path, we can omit the call also and handle
non-directories when rmdir errno is ENOTDIR.
For the recursive case we can avoid recursion when the top level path rmdir
succeeds immediately.
FileSystemEntry is updated so IsSymbolicLink remembers the file is symbolic link
and does not make a syscall for it.
Adds two new jobs to runtime-staging for Windows - AOT, and Wasm.Build.Tests.
AOT - runs with the same conditions as the one in runtime
Wasm.Build.Tests - run for rolling builds, or when a narrow set of paths related to wasm build change
And do this for corresponding job in runtime for linux
Co-authored-by: Alexander Köplinger <[email protected]>
* FileSystemEntry.Unix: ensure attributes are available when file is deleted.
When the file no longer exists, we create attributes based on what we know.
The test for this was passing because it cached the attributes before the
item was deleted due to enumerating with skipping FileAttributes.Hidden.
* GetLength: fix reading from uninitialized cache.
* switch from FileStream to RandomAccess
* use Array.MaxLength as a limit for File.ReadAllBytes and fix an edge case bug for files: Array.MaxLength < Length < int.MaxValue
* there is no gain of using FileOptions.SequentialScan on Unix, as it requires an additional sys call
Co-authored-by: Dan Moseley <[email protected]>
* Implement most of the fix for #38824
Reverts the changes in the seperate PR https://github.com/dotnet/runtime/commit/a617a01195b4dad3cb5f300962ad843b46d4f175 to fix#38824.
Does not re-enable the test because that relies on #49555, will add a seperate commit to whichever is merged last to enable the SettingUpdatesPropertiesOnSymlink test.
* Most of the code for PR #52639 to fix#38824
• Deal with merge conflicts
• Add FSOPT_NOFOLLOW for macOS and use it in setattrlist
• Use AT_SYMLINK_NOFOLLOW with utimensat (note: there doesn't seem to be an equivalent for utimes)
• Add SettingUpdatesPropertiesOnSymlink test to test if it actually sets it on the symlink itself (to the best that we can anyway ie. write + read the times)
• Specify FILE_FLAG_OPEN_REPARSE_POINT for CreateFile in FileSystem.Windows.cs (is there any other CreateFile calls that need this?)
* Remove additional FILE_FLAG_OPEN_REPARSE_POINT
I added FILE_FLAG_OPEN_REPARSE_POINT before and it was then added in another PR, this removes the duplicate entry.
* Add missing override keywords
Add missing override keywords for abstract members in the tests.
* Fix access modifiers
Fix access modifiers for tests - were meant to be protected rather than public
* Add more symlink tests, rearrange files
• Move symlink creation api to better spot in non-base files
• Add IsDirectory property for some of the new tests
• Change abstract symlink api to CreateSymlink that accepts path and target
• Create a CreateSymlinkToItem method that creates a symlink to an item that may be relative that uses the new/modified abstract CreateSymlink method
• Add SettingUpdatesPropertiesCore to avoid code duplication
• Add tests for the following variants: normal/symlink, target exists/doesn't exist, absolute/relative target
• Exclude nonexistent symlink target tests on Unix for Directories since they are counted as files
* Fix return type of CreateSymlink in File/GetSetTimes.cs
* Remove browser from new symlink tests as it doesn't support creation of symlinks
Remove browser from new symlink tests as it doesn't support creation of symlinks
* Use lutimes, improve code readability, simplify tests
• Use lutimes when it's available
• Extract dwFlagsAndAttributes to a variable
• Use same year for all tests
• Checking to delete old symlink is unnecessary, so don't
• Replace var with explicit type
* Change year in test to 2014 to reduce diff
* Rename symlink tests, use 1 core symlink times function, and check that target times don't change
Rename symlink tests, use 1 core symlink times function, and check that target times don't change
* Inline RunSymlinkTestPart 'function'
Inline RunSymlinkTestPart 'function' so that the code can be reordered so the access time test can be valid.
* Share CreateSymlinkToItem call in tests and update comment for clarity
* Update symlink time tests
• Make SettingUpdatesPropertiesOnSymlink a theory
• Remove special case for Unix due to https://github.com/dotnet/runtime/pull/52639#discussion_r739009259 (will revert if fails)
• Rename isRelative to targetIsRelative for clarity
* Remove unnecessary Assert.All
* Changes to SettingUpdatesPropertiesOnSymlink test
• Rename item field to link field
• Don't use if one-liner
• Use all time functions since only using UTC isn't necessary
• Remove the now-defunct IsDirectory property since we aren't checking it anymore
* Remove unnecessary fsi.Refresh()
• Remove unnecessary fsi.Refresh() since atime is only updated when reading a file
* Updates to test and pal_time.c
• Remove targetIsRelative cases
• Multi-line if statement
• Combine HAVE_LUTIMES and #else conditions to allow more code charing
* Remove trailing space
Update slngen tooling to latest stable version and solution files since
a lot changed since the last time they were updated:
- NET7 (removal of older TFMs)
- Source Generators
* Fix setting creation date for OSX
Fix for #39132
* Fix setting creation date for OSX - fix for setattrlist
This commit adds a fallback for setattrlist failing.
It can sometimes fail on specific volume types, so this is a workaround to use the old behaviour on unsupported filesystems.
Fix for #39132
* Fix setting creation date for OSX - fix for caching when set time & possible stack overflow
This commit adds _fileStatusInitialized = -1; which resets the cache for the file status after setting a time value to the file using the setattrlist api version so that it will not simply return the last cached time.
It also fixes SetCreationTime_OtherUnix method so that it calls SetLastWriteTime_OtherUnix directly instead of SetLastWriteTime because otherwise you'll get stuck in an infinite loop on OSX when the fallback is theoretically needed.
Fix for #39132
* Fix setting creation date for OSX - changes for PR 1
Fix the behaviour of SetLastWriteTime (OSX) when setting lastwritetime before creationtime.
Use Invalidate() instead of _fileStatusInitialized = -1, and only when appropriate as per PR #49555.
Add SettingUpdatesPropertiesAfterAnother test to test things such as setting lastwritetime to before creationtime.
Rename the added _OtherUnix methods to _StandardUnixImpl, a more logical name given their purpose (#49555)
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - changes for PR 2
Added a new test to test the behaviour of the file time functions on symlinks as per standard Windows behaviour, and also what I use in my code today. It makes sure that the times are set on the symlink itself, not the target. It is likely to fail on many unix platforms, so these will be given the [ActiveIssue] attribute when we discover which ones.
Make access time be set using setattrlist on OSX to fix following symlinks issue that would've failed the new test.
Fix and update wording of comment in SetAccessOrWriteTime.
Add T CreateSymlinkToItem(T item) to BaseGetSetTimes<T> (and implementation in inheritors) for the new test.
Made the SettingUpdatesPropertiesAfterAnother test skip on browser since it only, in effect, has one date attribute.
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - changes for PR 3
Revert change in last commit: Make access time be set using setattrlist on OSX to fix following symlinks issue that would've failed the new test. It is now using the other API as otherwise some file watcher tests fail.
Set AT_SYMLINK_NOFOLLOW in pal_time.c to not follow symlinks for access time on OSX, or any times on other unix systems.
* Fix setting creation date for OSX - fix test for Windows and browser + update comments
Fix the SettingUpdatesPropertiesOnSymlink test for Windows by setting FILE_FLAG_OPEN_REPARSE_POINT in the CreateFile used for setting times.
Disable the SettingUpdatesPropertiesOnSymlink test for Browser as it can't use symlinks with the current API in the test project.
Update comments.
Add FILE_FLAG_OPEN_REPARSE_POINT.
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - make modification time use normal unix APIs
Only implement creation time setting with setattrlist.
Here is why: eg. the old code doesn't account for setting creation time to 2002, then setting modification time to 2001, and then setting access time (since access time didn't have the creation date check).
I've split up SetAccessOrWriteTime into 3 parts - SetAccessOrWriteTime, SetAccessOrWriteTime_StandardUnixImpl, and SetAccessOrWriteTimeImpl (this last one contains the logic of the method without the things like refreshing the times so it's not called twice on OSX). In this process I replaced the _fileStatusInitialized = -1 calls with Invalidate() calls. And to make sure that if the creation time is needed to be set by SetAccessOrWriteTime, then we don't get in an infinite loop in case setattrlist fails, so we call SetAccessOrWriteTime_StandardUnixImpl.
* Fix setting creation date for OSX - hotfix: Remove ATTR_CMN_MODTIME
Adding this commit now to avoid 2x CI.
It was meant to be in the last one, but I forgot to save the file.
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - revert windows changes & simplify code
Revert the changes for Windows & disable the SettingUpdatesPropertiesOnSymlink test on Windows.
Remove unnecessary setting to 0 on the attrList variable.
Remove the unnecessary MarshalAs attributes in the AttrList type.
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - hotfix: change to CULong for marshalling with setattrlist
Use CULong as per https://github.com/dotnet/runtime/pull/49555#discussion_r599986776
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - hotfix: change to CULong for marshalling with setattrlist 2
Use CULong as per #49555 (comment)
Forgot to save the other file's changes
Fix for #39132 and issues in #49555.
* Fix setting creation date for OSX - consolidate unix nanosecond calculation
Consolidate unix nanosecond calculation into UnixTimeSecondsToNanoseconds as per https://github.com/dotnet/runtime/pull/49555#discussion_r600004629.
Fix for #39132 and issues in #49555.
* Use InvalidateCaches instead of Invalidate and EnsureCachesInitialized instead of EnsureStatInitialized
* Fixes for reviews in PR #49555
Add an identifying field to the TimeFunction tuple and a function to get a TimeFunction from the name.
This function is then used so that SettingUpdatesPropertiesAfterAnother can be written as a Theory, and is a lot more readable.
Fix some comments that were incorrect.
* Hotfix for missing parameter
* Fix naming
* Revert changes re SettingUpdatesPropertiesAfterAnother (mainly) and revert using a Theory
Reversion as per https://github.com/dotnet/runtime/pull/49555#discussion_r633895912
This change can be unreverted if that's what's decided.
* Fix errors of #49555 due to missing variables
* Remove the parameters that were meant to be removed
* Finish merge
* Remove duplicate file
* Add custom error handling for setattrlist
Add custom error handling for setattrlist as per https://github.com/dotnet/runtime/pull/49555#discussion_r633788259.
ENOTDIR means it is not a directory, so directory not found seems logical to me, I think the other errors can be dealt with by an IOException, happy to change this.
* Remove symlink specific code from this PR
Removes the symlink specific code as per https://github.com/dotnet/runtime/pull/49555#issuecomment-904413721.
This will be reverted (and modified) as per https://github.com/dotnet/runtime/pull/49555#issuecomment-904413721 into #52639.
* Remove custom ENOTDIR handling, enable tests for other OSX-like platforms + move items in project file
• Removed ENOTDIR handling as per https://github.com/dotnet/runtime/pull/49555#discussion_r705012504
• Enabled tests for other OSX-like platforms since the code was included on them (IsOSXLike is presumably defined at src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs). If it fails on any of these platforms, they'll be fully explicitly excluded everywhere for this PR or fixed.
• Move item in project file (System.Private.CoreLib.Shared.projitems) as per https://github.com/dotnet/runtime/pull/49555#discussion_r705032218
* Rename files according to review
Rename files according to https://github.com/dotnet/runtime/pull/49555#discussion_r705073538 (and nearby comments).
* Change names of functions to improve readability and refactor code
This commit changes and refactors the core functions of this PR to have clearer names and to create a more logical flow of the code. It also updates some comments and fixes some oversights. Changes are based on the discussion https://github.com/dotnet/runtime/pull/49555#discussion_r705180391 (read whole conversation).
* Fix the wrongly named variable and add the missing 'unsafe' keyword
Fix the wrongly named variable and add the missing 'unsafe' keyword
* Better comments and minor improvements
Changes according to https://github.com/dotnet/runtime/pull/49555#pullrequestreview-753354257
• Use explicit type `IEnumerable<TimeFunction>` instead of var
• Use PlatformDetection rather than OperatingSystem
• Move the InvalidateCaches code for creation time setting to avoid unnecessary checks
• Update explanatory comments to be more useful
* Add additional tests and improvements
- Use tuple destruction to swap variables
- Add SettingOneTimeMaintainsOtherDefaultTimes and AllDefaultTimesAreSame test as per https://github.com/dotnet/runtime/pull/49555#discussion_r712787328
- Change TFM(/s) as per https://github.com/dotnet/runtime/pull/49555#discussion_r717042126
- Avoid unnecessary call to `UnixTimeToDateTimeOffset` as per https://github.com/dotnet/runtime/pull/49555#discussion_r712606875
- Use InvalidOperationException as per https://github.com/dotnet/runtime/pull/49555#discussion_r717040240
* Fix typos
* Revert to <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
Revert to using <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks> since <TargetFramework>$(NetCoreAppCurrent)</TargetFramework> failed; I wouldn't be surprised if this failed too.
* Remove SettingOneTimeMaintainsOtherDefaultTimes and AllDefaultTimesAreSame tests
Remove SettingOneTimeMaintainsOtherDefaultTimes and AllDefaultTimesAreSame tests since they don't work on windows because it is apparently an invalid time. Additionally, the function SettingOneTimeMaintainsOtherDefaultTimes wasn't working and needed to be fixed.
* Fix: setattrlist can only return 0 or -1
As per https://github.com/dotnet/runtime/pull/49555#discussion_r731451808, use GetLastErrorInfo to get the error when setattrlist indicates that there is one.
Co-authored-by: David Cantú <[email protected]>
* Update code comment for SettingUpdatesPropertiesAfterAnother test
The comment is now clearer and grammatically correct :)
* Update code comment for SettingUpdatesPropertiesAfterAnother test
Describe how utimensat change more dates than would be desired
* Update comment for SettingUpdatesPropertiesAfterAnother for consistency
Update for consistency with the comment in FileStatus.Unix.cs
* Fixes for compilation and update to comment
• Fix trailing spaces and incorrect capitalisation in FileStatus.SetTimes.OSX.cs
• Add more info to the comment in the SettingUpdatesPropertiesAfterAnother test
* Update FileStatus.SetTimes.OSX.cs
Use the Error property
* Move comments and add explicit types to SettingUpdatesPropertiesAfterAnother test
Move comments and add explicit types to SettingUpdatesPropertiesAfterAnother test
Co-authored-by: David Cantú <[email protected]>
* add a failing test
* fix the bug in BufferedFileStreamStrategy
* extend the test and fix it in the BufferedStream as well
* large files are currently not supported on WASM
* Apply suggestions from code review
Co-authored-by: Carlos Sanchez <[email protected]>
Co-authored-by: Carlos Sanchez <[email protected]>
* shorten the timeout
* try to reorder the operations
* Revert "try to reorder the operations"
This reverts commit 413ee9b14f114246fc5659d4a1515e6fefc21cd2.
* disable the test for now
* Allocate an array of memory handles only if needed.
* Remove an unnecessary variable in the multiple-syscall write gather.
* Actually verify the content read by the read scatter operation.
* Delay allocating native memory.
* Verify that the whole file was read in the scatter/gather test.
* Test the case when the scatter/gather buffers are acceptable by the Windows API.
* Avoid null pointer dereferences when passing an empty segment array.
* Test performing scatter/gather I/O with an empty segment array.
Co-authored-by: Stephen Toub <[email protected]>
* Fallback to read/write if pread/pwrite fails
* * Cache whether a handle supports random access
* Keep avoiding pread/pwrite for unseekable files
* Fallback to read/write only for known error ENXIO
* Test more device paths and add tests for WriteAll*
* Fix CI: skip test when device can't be opened
* * Do not use SkipTestException
* Exclude EBADF from assertion
* use NullableBool in _supportsRandomAccess
* Add tests for mkfifo and socketpair
* Rename test file
* Address feedback in src
* Address suggestions
* Address suggestions
* Update src/libraries/System.IO.FileSystem/tests/FileStream/DevicesPipesAndSockets.cs
Use Lazy for thread-safety
Co-authored-by: Adam Sitnik <[email protected]>
* Use IEnumerable<string> in Lazy and fix usages
Co-authored-by: David Cantu <[email protected]>
Co-authored-by: Adam Sitnik <[email protected]>
* FileStream.Unix: improve DeleteOnClose when FileShare.None.
Use FileShare.None lock to detect when another Handle that has
DeleteOnClose deleted the file, and then re-open it.
* Rephrase comment
* FileStream_DeleteOnClose: handle a few special cases.
* Try avoiding test timeout on arm
* Limit check to filemodes that open an existing file, or create it when it doesn't exist.
* PR feedback
* Limit functional change to FileMode.OpenOrCreate, and increase test timeout.
* Fix comment.
Co-authored-by: Carlos Sanchez <[email protected]>
Co-authored-by: Carlos Sanchez <[email protected]>
* File preallocationSize: align Windows and Unix behavior.
This aligns Windows and Unix behavior of preallocationSize for the
intended use-case of specifing the size of a file that will be written.
For this use-case, the expected FileAccess is Write, and the file should be
a new one (FileMode.Create*) or a truncated file (FileMode.Truncate).
Specifing a preallocationSize for other modes, or non-writable files throws ArgumentException.
The opened file will have a length of zero, and is ready to be written to by the user.
If the requested size cannot be allocated, an IOException is thrown.
When the OS/filesystem does not support pre-allocating, preallocationSize is ignored.
* fix pal_io preprocessor checks
* pal_io more fixes
* ctor_options_as.Windows.cs: fix compilation
* Update tests
* tests: use preallocationSize from all public APIs
* pal_io: add back FreeBSD, fix OSX
* tests: check allocated is zero when preallocation is not supported.
* Only throw for not enough space errors
* Fix compilation
* Add some more tests
* Fix ExtendedPathsAreSupported test
* Apply suggestions from code review
Co-authored-by: David Cantú <[email protected]>
* Update System.Private.CoreLib Strings.resx
* PR feedback
* Remove GetPathToNonExistingFile
* Fix compilation
* Skip checking allocated size on mobile platforms.
Co-authored-by: David Cantú <[email protected]>
* NT prefix shall not be treated as a relative path
* Remove file-folder-match validation
* Use SubstituteName instead of PrintName since the latter is just for display and can be misleading
* Fix MS.IO.Redist
* Fix whitespace in Strings.resx
* Address suggestions
With the newest udpate of slngen, the order of elements (configuration, folders, etc.) is in sync with how Visual Studio arranges them.
Also the order is now deterministic.
Based on that, updating all solution files to have the correct ordering of elements. This change also unblocks adding CI protection for
making sure that solution files are up-to-date in regards to their dependencies as slngen is now generating the files deterministically.
* Add mount point support to link APIs.
* Add junction and virtual drive tests.
* Move PrintName comment outside of if else of reparseTag check.
* Add Windows platform specific attribute to junction and virtual drive test classes.
* Revert FILE_NAME_OPENED to FILE_NAME_NORMALIZED
* Revert addition of FILE_NAME_OPENED const.
* Remove unnecessary enumeration junction test.
* Rename GetNewCwdPath to ChangeCurrentDirectory
* Make Junction_ResolveLinkTarget a theory and test both resolveFinalTarget
* Shorter name for targetPath string. Typo in comment. Fix Debug.Assert.
* Clarify test comment. Change PlatformDetection for OperatingSystem check.
* Cleaner unit tests for virtual drive, add indirection test
* Skip virtual drive tests in Windows Nano (subst not available). Small test rename.
* Simplify Junctions tests, add indirection test
* Address test suggestions.
* Revert MountHelper.CreateSymbolicLink changes. Unrelated, and will be refactored/removed in the future.
Detect if SUBST is available in Windows machine, to bring back Nano.
* Add dwReserved0 check for mount points in GetFinalLinkTarget.
* Use Yoda we don't.
* Fix CI issues
Co-authored-by: carlossanlop <[email protected]>
Co-authored-by: David Cantu <[email protected]>
* Remove validation to stat call for symlinks since is a breaking change, subsequently remove the symlink cache logic as is no longer needed
* Undo try-catch workaround in PhysicalFileProvider
* Fix tests that were failing due to changes
All this changes are to internal methods which are later called by other public methods which correctly call `ToLocalTime` for local time "overloads".
Performance hit is most visible for application which doesn't need to load local timezone information which takes ~30ms on 2016 MacBook Pro.
Co-authored-by: Jeff Handley <[email protected]>