* fractional file timestamps in tramp-adb
@ 2019-02-14 18:43 Paul Eggert
2019-02-14 20:23 ` Michael Albinus
0 siblings, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2019-02-14 18:43 UTC (permalink / raw)
To: Michael Albinus; +Cc: Emacs development discussions
[-- Attachment #1: Type: text/plain, Size: 629 bytes --]
The attached recently-installed patchchanges the tramp-adb's generated
shell command from this format:
touch -t 201902141023.17 file
to this format:
touch -d 2019-02-14T18:23:17 file
A downside of the new approach is that it assumes POSIX.1-2008 or later,
but I guess that's OK nowadays. An upside is that 'touch -d' lets one
specify the fractional part of the timestamp, and also lets one specify
that the timestamp is UTC by appending "Z" (I don't see how the current
code is arranging for UTC). So, how about the attached followup patch?
It would change the format to:
touch -d 2019-02-14T18:23:17.318491822Z file
[-- Attachment #2: 0001-Add-fractional-file-timestamps-to-tramp-adb.patch --]
[-- Type: text/x-patch, Size: 905 bytes --]
From 68d572c9b6869556f02ca1118025b94d27723aa4 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 14 Feb 2019 10:40:37 -0800
Subject: [PATCH] Add fractional file timestamps to tramp-adb
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times):
Set fractional part of file timestamp too. Specify UTC.
---
lisp/net/tramp-adb.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 22f2c5f6bf..5dbcf55067 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -680,7 +680,7 @@ tramp-adb-handle-set-file-times
time)))
(tramp-adb-send-command-and-check
v (format "touch -d %s %s"
- (format-time-string "%Y-%m-%dT%H:%M:%S" time t)
+ (format-time-string "%Y-%m-%dT%H:%M:%S.%NZ" time t)
(tramp-shell-quote-argument localname))))))
(defun tramp-adb-handle-copy-file
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: fractional file timestamps in tramp-adb
2019-02-14 18:43 fractional file timestamps in tramp-adb Paul Eggert
@ 2019-02-14 20:23 ` Michael Albinus
2019-02-14 23:41 ` Paul Eggert
0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2019-02-14 20:23 UTC (permalink / raw)
To: Paul Eggert; +Cc: Emacs development discussions
Paul Eggert <eggert@cs.ucla.edu> writes:
Hi Paul,
> A downside of the new approach is that it assumes POSIX.1-2008 or
> later, but I guess that's OK nowadays. An upside is that 'touch -d'
> lets one specify the fractional part of the timestamp, and also lets
> one specify that the timestamp is UTC by appending "Z" (I don't see
> how the current code is arranging for UTC). So, how about the attached
> followup patch? It would change the format to:
>
> touch -d 2019-02-14T18:23:17.318491822Z file
It doesn't work, at least on my Galaxy S6:
--8<---------------cut here---------------start------------->8---
$ touch -d 2019-02-14T18:23:17.318491822Z /sdcard/tmp/foo
touch: bad '2019-02-14T18:23:17.318491822': Value too large for defined data type
--8<---------------cut here---------------end--------------->8---
It runs Android 7.0, as identified by Tramp:
--8<---------------cut here---------------start------------->8---
$ echo \"`getprop ro.product.model` `getprop ro.product.version` `getprop ro.build.version.release`\"
"SM-G920F 7.0"
--8<---------------cut here---------------end--------------->8---
OTOH, touch doesn't work at all on my device, because it isn't rooted:
--8<---------------cut here---------------start------------->8---
$ touch -d 2019-02-14T18:23:17 /sdcard/tmp/foo
touch: '/sdcard/tmp/foo': Operation not permitted
--8<---------------cut here---------------end--------------->8---
But that's another story; I don't want to modify my device that way.
Best regards, Michael.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fractional file timestamps in tramp-adb
2019-02-14 20:23 ` Michael Albinus
@ 2019-02-14 23:41 ` Paul Eggert
2019-02-15 8:11 ` Michael Albinus
0 siblings, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2019-02-14 23:41 UTC (permalink / raw)
To: Michael Albinus; +Cc: Emacs development discussions
On 2/14/19 12:23 PM, Michael Albinus wrote:
> It doesn't work, at least on my Galaxy S6: --8<---------------cut
> here---------------start------------->8--- $ touch -d
> 2019-02-14T18:23:17.318491822Z /sdcard/tmp/foo touch: bad
> '2019-02-14T18:23:17.318491822': Value too large for defined data type
>
Interesting. Does it work without the ".318491822" but keep the "Z"?
How about if you replace ".31849182" with ".000000000" while keeping the
"Z"?
Can you strace the 'touch' and see what system calls are failing and
what their arguments are? On my platform, if the file /tmp/foo already
exists and is writeable, then the command:
strace touch -d 2019-02-14T18:23:17.318491822Z /tmp/foo
outputs:
...
openat(AT_FDCWD, "/tmp/foo", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
dup2(3, 0) = 0
close(3) = 0
utimensat(0, NULL, [{tv_sec=1550168597, tv_nsec=318491822} /* 2019-02-14T10:23:17.318491822-0800 */, {tv_sec=1550168597, tv_nsec=318491822} /* 2019-02-14T10:23:17.318491822-0800 */], 0) = 0
...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fractional file timestamps in tramp-adb
2019-02-14 23:41 ` Paul Eggert
@ 2019-02-15 8:11 ` Michael Albinus
2019-02-15 22:37 ` Paul Eggert
0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2019-02-15 8:11 UTC (permalink / raw)
To: Paul Eggert; +Cc: Emacs development discussions
Paul Eggert <eggert@cs.ucla.edu> writes:
Hi Paul,
> Interesting. Does it work without the ".318491822" but keep the "Z"?
Yes.
--8<---------------cut here---------------start------------->8---
$ touch -d 2019-02-14T18:23:17.318491822 /sdcard/tmp/foo
touch: '/sdcard/tmp/foo': Operation not permitted
--8<---------------cut here---------------end--------------->8---
> How about if you replace ".31849182" with ".000000000" while keeping
> the "Z"?
Doesn't work.
--8<---------------cut here---------------start------------->8---
$ touch -d 2019-02-14T18:23:17.000000000Z /sdcard/tmp/foo
touch: bad '2019-02-14T18:23:17.000000000': Value too large for defined data type
--8<---------------cut here---------------end--------------->8---
> Can you strace the 'touch' and see what system calls are failing and
> what their arguments are?
There's no strace on my Galaxy.
In older Android versions, most of the coreutils were implemented via
busybox. This has been replaced by toybox:
--8<---------------cut here---------------start------------->8---
$ which touch
/system/bin/touch
$ ls -l /system/bin/touch
lrwxrwxrwx 1 root root 6 2016-03-25 17:04 /system/bin/touch -> toybox
$ toybox --version
0.7.0--android
--8<---------------cut here---------------end--------------->8---
See also <https://lwn.net/Articles/629362/>. tramp-adb.el has already
some few checks for toybox, but not systematically. I suspect we need to
do it better, due to the differences in command parameters, and their
output.
I'm afraid, I'm not an experienced Android developer (tramp-adb.el was
written by somebody else). Any help appreciated!
Best regards, Michael.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fractional file timestamps in tramp-adb
2019-02-15 8:11 ` Michael Albinus
@ 2019-02-15 22:37 ` Paul Eggert
2019-02-16 8:33 ` Michael Albinus
0 siblings, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2019-02-15 22:37 UTC (permalink / raw)
To: Michael Albinus; +Cc: Emacs development discussions
[-- Attachment #1: Type: text/plain, Size: 525 bytes --]
On 2/15/19 12:11 AM, Michael Albinus wrote:
> I'm afraid, I'm not an experienced Android developer (tramp-adb.el was
> written by somebody else). Any help appreciated!
Older versions of toybox touch mishandle nanoseconds, and perhaps you've
run into one of those. How about the attached patch, to try fractional
timestamps (with "Z" for UTC) if it works, and fall back on the existing
code otherwise? Plus, we can fall back on touch -t for hosts that don't
yet support POSIX-2008, though that may be overkill nowadays.
[-- Attachment #2: 0001-Port-tramp-adb-to-various-touch-platforms.patch --]
[-- Type: text/x-patch, Size: 1683 bytes --]
From c4dad9e5d60153870cca647ece7e266b4eb4e19e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 15 Feb 2019 14:36:30 -0800
Subject: [PATCH] Port tramp-adb to various 'touch' platforms
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times):
Try nanoseconds first, then plain seconds, then touch -t.
---
lisp/net/tramp-adb.el | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 22f2c5f6bf..4fba4e14f3 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -677,11 +677,22 @@ tramp-adb-handle-set-file-times
(tramp-compat-time-equal-p time tramp-time-doesnt-exist)
(tramp-compat-time-equal-p time tramp-time-dont-know))
(current-time)
- time)))
+ time))
+ (quoted-name (tramp-shell-quote-argument localname)))
+ ;; Older versions of toybox 'touch' mishandle nanoseconds and/or
+ ;; trailing "Z", so fall back on plain seconds if nanoseconds+Z
+ ;; fails. Also, fall back on old POSIX 'touch -t' if 'touch -d'
+ ;; (introduced in POSIX.1-2008) fails.
(tramp-adb-send-command-and-check
- v (format "touch -d %s %s"
+ v (format (concat "touch -d %s %s 2>/dev/null || "
+ "touch -d %s %s 2>/dev/null || "
+ "touch -t %s %s")
+ (format-time-string "%Y-%m-%dT%H:%M:%S.%NZ" time t)
+ quoted-name
(format-time-string "%Y-%m-%dT%H:%M:%S" time t)
- (tramp-shell-quote-argument localname))))))
+ quoted-name
+ (format-time-string "%Y%m%d%H%M.%S" time t)
+ quoted-name)))))
(defun tramp-adb-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: fractional file timestamps in tramp-adb
2019-02-15 22:37 ` Paul Eggert
@ 2019-02-16 8:33 ` Michael Albinus
0 siblings, 0 replies; 6+ messages in thread
From: Michael Albinus @ 2019-02-16 8:33 UTC (permalink / raw)
To: Paul Eggert; +Cc: Emacs development discussions
Paul Eggert <eggert@cs.ucla.edu> writes:
Hi Paul,
> Older versions of toybox touch mishandle nanoseconds, and perhaps
> you've run into one of those. How about the attached patch, to try
> fractional timestamps (with "Z" for UTC) if it works, and fall back on
> the existing code otherwise? Plus, we can fall back on touch -t for
> hosts that don't yet support POSIX-2008, though that may be overkill
> nowadays.
Looks good. I've pushed it to both Emacs and Tramp repositories, in your
name.
A further improvement could be to check once, after connection is
established, which touch flavor works, and to apply only this
pattern. Otherwise, on non-rooted devices (like my Galaxy S6) all touch
versions are always applied, because they fail at least with "permission
denied".
But I don't know whether this is worth the effort ...
Thanks, and best regards, Michael.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-02-16 8:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-14 18:43 fractional file timestamps in tramp-adb Paul Eggert
2019-02-14 20:23 ` Michael Albinus
2019-02-14 23:41 ` Paul Eggert
2019-02-15 8:11 ` Michael Albinus
2019-02-15 22:37 ` Paul Eggert
2019-02-16 8:33 ` Michael Albinus
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).