Skip to content

Conversation

@dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Mar 6, 2018

DevDiv Issue 571365

We have a report that ConvertResourcesCases is failing with the follow
error.

error MSB4018: The "ConvertResourcesCases" task failed unexpectedly.
Android/Xamarin.Android.Common.targets(1334,2): error MSB4018: System.IO.FileNotFoundException: <some path>/design_layout_snackbar.xml.tmp does not exist

This is completely weird, especially as the Task is not called in
parallel. What I susepct is happening is VSForMac is running is
UpdateResources task at the same time the user is doing a build.

Because the name of the temp files we are just foo.xml.tmp it
is highly possible that one instance of the task is deleting the
file while the other instance is still running. This is difficult
to replicate.

This change uses

System.IO.Path.GetTempFileName ();

to generate a random temp file name for the temp file. This should
stop filename collisions since the file will end up in the /tmp directory.

… unexpectedly.

DevDiv Issue 571365

We have a report that `ConvertResourcesCases` is failing with the follow
error.

	error MSB4018: The "ConvertResourcesCases" task failed unexpectedly.
	Android/Xamarin.Android.Common.targets(1334,2): error MSB4018: System.IO.FileNotFoundException: <some path>/design_layout_snackbar.xml.tmp does not exist

This is completely weird, especially as the Task is not called in
parallel. What I susepct is happening is VSForMac is running is
UpdateResources task at the same time the user is doing a build.

Because the name of the temp files we are just `foo.xml.tmp` it
is highly possible that one instance of the task is deleting the
file while the other instance is still running. This is difficult
to replicate.

This change uses

	System.IO.Path.GetFileName (System.IO.Path.GetTempFileName ());

to generate a random temp file name for the temp file. This should
stop filename collisions.
@dellis1972 dellis1972 added the do-not-merge PR should not be merged. label Mar 6, 2018
Log.LogDebugMessage (" Processing: {0}", file);
var srcmodifiedDate = File.GetLastWriteTimeUtc (file);
var tmpdest = file + ".tmp";
var tmpdest = file + "_" + Path.GetFileName (Path.GetTempFileName ());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair idea, not-quite-write implementation.

Did you know that Path.GetTempFileName() creates the file?

This method creates a temporary file with a .TMP file extension.

For example:

var p = Path.GetTempFileName();
// p == e.g. "/var/folders/1y/wwmg3hv5685ft661f5q2w2100000gn/T/tmpa1d2e05.tmp"
File.Exists(p); // is true

As such, Path.GetFileName(Path.GetTempFileName()) will "litter" the user's %TMPDIR% directory with temporary files which are never deleted.

Instead, we should just do:

var tempest = Path.GetTempFileName ();

We'll properly delete this file in the finally block below.

@jonpryor
Copy link
Contributor

jonpryor commented Mar 7, 2018

The macOS+xbuild PR Build is failing:

Resources/drawable/android_button.xml(2): error APT0000: No resource found that matches the given name (at 'drawable' with value '@drawable/AndroidPressed').

@dellis1972
Copy link
Contributor Author

@jonpryor
Copy link
Contributor

jonpryor commented Mar 7, 2018

@dean: sounds like we should crib the Path.GetTempFileName() code so that we can supply the directory it creates the file in. ;-)

@dellis1972 dellis1972 removed the do-not-merge PR should not be merged. label Mar 8, 2018
@jonpryor jonpryor merged commit b0f4dea into dotnet:master Mar 8, 2018
jonpryor pushed a commit that referenced this pull request Mar 9, 2018
… unexpectedly. (#1371)

Fixes? https://devdiv.visualstudio.com/DevDiv/_workitems/edit/571365

We have a report that `ConvertResourcesCases` is failing with the
following error:

	error MSB4018: The "ConvertResourcesCases" task failed unexpectedly.
	Android/Xamarin.Android.Common.targets(1334,2): error MSB4018: System.IO.FileNotFoundException: <some path>/design_layout_snackbar.xml.tmp does not exist

This is completely weird, especially as the Task is not being called
concurrently (or so we hope & assume). What I suspect is happening is
Visual Studio for Mac is running the `UpdateAndroidResources` target
at the same time the user started a build.

Because the name of the temp files was just `foo.xml.tmp` it is
highly possible that one instance of the task is deleting the file
while another instance is still running. This is difficult to
replicate.

Attempt to "fix" things by using `System.IO.Path.GetTempFileName()`
instead of appending `.tmp` to the filename. This should avoid
filename collisions.

However, if our suspicion is correct that the `UpdateAndroidResources`
target is concurrently executing alongside a Build, this patch will
*not* fix the concurrent target execution scenario.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants