Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tvOS] Environment.GetSpecialFolder is too eager in creating the special directories #58787

Closed
filipnavara opened this issue Sep 8, 2021 · 2 comments · Fixed by #58788
Closed
Labels
Milestone

Comments

@filipnavara
Copy link
Member

PR #57508 added the following code:

#if TARGET_TVOS
string? path = CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, Path.Combine("Caches", "Documents", subdirectory));
// Special version of CombineSearchPath which creates the path if needed.
// This isn't needed for "real" search paths which always exist, but on tvOS
// the base path is really a subdirectory we define rather than an OS directory.
// In order to not treat Directory.Exists(SpecialFolder.ApplicationData) differently
// on tvOS, guarantee that it exists by creating it here
if (!Directory.Exists (path))
Directory.CreateDirectory (path);
#else

While the intention to create ApplicationData directory is correct the implementation creates also any subdirectory as well which is different from what legacy Mono did and what iOS does.

The expected version of the code should be closer to

                string? path = CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, Path.Combine("Caches", "Documents"));
                // Special version of CombineSearchPath which creates the path if needed.
                // This isn't needed for "real" search paths which always exist, but on tvOS
                // the base path is really a subdirectory we define rather than an OS directory.
                // In order to not treat Directory.Exists(SpecialFolder.ApplicationData) differently
                // on tvOS, guarantee that it exists by creating it here
                if (!Directory.Exists (path))
                    Directory.CreateDirectory (path);
                path = Path.Combine(path, subdirectory);

(ie. only create the base directory and then combine the paths)

Ref: xamarin/xamarin-macios#12640

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Sep 8, 2021
@ghost
Copy link

ghost commented Sep 8, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

PR #57508 added the following code:

#if TARGET_TVOS
string? path = CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, Path.Combine("Caches", "Documents", subdirectory));
// Special version of CombineSearchPath which creates the path if needed.
// This isn't needed for "real" search paths which always exist, but on tvOS
// the base path is really a subdirectory we define rather than an OS directory.
// In order to not treat Directory.Exists(SpecialFolder.ApplicationData) differently
// on tvOS, guarantee that it exists by creating it here
if (!Directory.Exists (path))
Directory.CreateDirectory (path);
#else

While the intention to create ApplicationData directory is correct the implementation creates also any subdirectory as well which is different from what legacy Mono did and what iOS does.

The expected version of the code should be closer to

                string? path = CombineSearchPath(NSSearchPathDirectory.NSLibraryDirectory, Path.Combine("Caches", "Documents"));
                // Special version of CombineSearchPath which creates the path if needed.
                // This isn't needed for "real" search paths which always exist, but on tvOS
                // the base path is really a subdirectory we define rather than an OS directory.
                // In order to not treat Directory.Exists(SpecialFolder.ApplicationData) differently
                // on tvOS, guarantee that it exists by creating it here
                if (!Directory.Exists (path))
                    Directory.CreateDirectory (path);
                path = Path.Combine(path, subdirectory);

(ie. only create the base directory and then combine the paths)

Ref: xamarin/xamarin-macios#12640

Author: filipnavara
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@filipnavara
Copy link
Member Author

filipnavara added a commit to filipnavara/runtime that referenced this issue Sep 8, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 8, 2021
@adamsitnik adamsitnik removed the untriaged New issue has not been triaged by the area owner label Sep 8, 2021
@marek-safar marek-safar added this to the 6.0.0 milestone Sep 8, 2021
@marek-safar marek-safar added the os-tvos Apple tvOS label Sep 8, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 13, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants