Bug 36326 - Do not chdir to app bundle Resources directory, or provide an embedding API to get the original CWD
Summary: Do not chdir to app bundle Resources directory, or provide an embedding API t...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Runtime ()
Version: 2.4.0 (C6)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-11-28 13:56 UTC by Aaron Bockover [MSFT]
Modified: 2015-12-01 15:26 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Aaron Bockover [MSFT] 2015-11-28 13:56:36 UTC
For whatever reason (it's not explained in launcher.h, launch step 3b), the launcher calls chdir on the main app bundle's Resources directory.

I cannot think of a reason to actually do this (Resources in particular is strange, since there's no requirement for it to have anything in it or exist at all inside the bundle). However, if there is it should:

a) be documented as to why
b) we should provide an embedding API to get the original CWD from when the app was first launched
Comment 2 Aaron Bockover [MSFT] 2015-11-28 14:00:41 UTC
As an example, I had to work around this in Conservatorio. The Mac app itself supports being run as a console application, where I really do care about the original CWD (where the user actually is in the shell):

https://github.com/abock/conservatorio/commit/7fa607dbdb41232b56344186ddb1aeac8854e3d7

If we _really_ do need to change to the Resources directory of the app bundle, an API like I've provided in xminit.c would be nice, so no native code needs to be written by the user. We would surface the P/Invoke as something like ObjCRuntime.Runtime.GetOriginalWorkingDirectory ().
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-11-30 09:01:53 UTC
It came from here: https://github.com/xamarin/maccore/commit/20045dd7f85cb038cea673a9281bb6131711069c#diff-a5f7b751fa9635fd48bad8402abce78dR141, but I couldn't track it further since I don't know where mmp came from.

Also it's not something that we can change now, since it's very likely apps depend on it, but adding an API to get the original CWD is a good idea.
Comment 4 Aaron Bockover [MSFT] 2015-11-30 14:44:16 UTC
Good point. I bet there are apps that do IO without specifying a directory path, assuming they're changed into Resources :-/
Comment 6 Aaron Bockover [MSFT] 2015-12-01 15:26:38 UTC
This is fixed in master. When released, Xamarin.Mac apps may use these new APIs:

ObjCRuntime.Runtime:
  void ChangeToOriginalWorkingDirectory ()
  string OriginalWorkingDirectory { get; }