Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 15010 [details]
The following sample app demonstrates an issue where setting the value for SetLastWriteTimeUtc will cause an exception to be thrown when ran on a device
# Steps to Reproduce
1. Download sample
2. Deploy to Android device
3. Click button
# Expected Results
File last write time should be changed to match value specified
# Actual Results
Exception is thrown as described
=== Xamarin Studio ===
Version 5.10.2 (build 56)
Installation UUID: 54cc62c4-f821-426e-b955-267e765e7bb9
Mono 4.2.2 (explicit/996df3c)
GTK+ 2.24.23 (Raleigh theme)
Package version: 402020030
=== Xamarin.Profiler ===
=== Xamarin.Android ===
Version: 126.96.36.199 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.0.3 (API level 15)
4.4 (API level 19)
6.0 (API level 23)
SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
=== Xamarin Android Player ===
Location: /Applications/Xamarin Android Player.app
=== Apple Developer Tools ===
Xcode 7.2.1 (9548.1)
=== Xamarin.iOS ===
Version: 188.8.131.52 (Business Edition)
Build date: 2016-01-29 16:59:11-0500
=== Xamarin.Mac ===
Version: 184.108.40.206 (Business Edition)
=== Build Information ===
Release ID: 510020056
Git revision: bb74ff467c62ded42b7b7ac7fdd2edc60f8647b0
Build date: 2016-01-26 16:24:41-05
Xamarin addins: 8b797d7ba24d5abab226c2cf9fda77f666263f1b
Build lane: monodevelop-lion-cycle6-c6sr1
=== Operating System ===
Mac OS X 10.11.3
Darwin clb-macbook.local 15.3.0 Darwin Kernel Version 15.3.0
Thu Dec 10 18:40:58 PST 2015
So, it appears this is not a bug, it's just the way Android works. Here's what happens. Your test app creates the file on the external storage filesystem which is a guarded FUSE system mounted on some directory in the filesystem. Guarded means that all the requests to access/create files/directories go through a proxy process which creates them with its own permissions/owner. The app can create/write/read the files and directories but any attempt to modify their metadata in a direct manner will fail. Here's the listing of directory and file created by the sample app:
flounder:/storage/emulated/0/TestApp $ ls -l hello.txt
-rw-rw---- 1 root sdcard_rw 12 2016-09-28 17:39 hello.txt
flounder:/storage/emulated/0/TestApp $ ls -ld .
drwxrwx--x 2 root sdcard_rw 4096 2016-08-31 19:57 .
Note the file/dir owners.
Below you can see the user the app is running as and the user's group membership:
flounder:/storage/emulated/0/TestApp $ ps|grep filewri
u0_a186 14382 1031 1696300 94856 futex_wait 0000000000 S com.companyname.filewritetest
flounder:/storage/emulated/0/TestApp $ id u0_a186
uid=10186(u0_a186) gid=10186(u0_a186) groups=10186(u0_a186), context=u:r:shell:s0
As a consequence, any attempt to set the modification time of the file (it eventually boils down to calling utime(2) deep in the Mono runtime) gets the EPERM (permission denied) error, and rightfully so.
What's interesting is that Android's own Java.IO.File class is also unable to set the file modification time (using https://developer.android.com/reference/java/io/File.html#setLastModified(long) )
Therefore the bug is not fixable :(
That's a shame. So is there no way, at all, in Android to set the last write time of a file? If not, I wonder how file sync software does it.
Not that I can see atm, at least not when it's stored in external storage. Files stored in internal storage can have their metadata modified. Sync software might be keeping tabs by using checksums and/or storing timestamps in sqlite (for instance).
It's also possible that there's a more indirect way to set the timestamp in the external storage case, but I haven't found one yet.