Hi,
Below is a patch that adds ID-FORMAT to file-attributes. It is posted
here for getting views on it (I'm not normally in this part of the
code).
Standard ChangeLogs items are missing and will be added.
Windows support is missing but should be possible to add by
implementing the proper qxe_getgrgid function. (Which I don't indent
to do without having the possibility to test it.)
Apart from that I wonder about the code that does call2 and call3 in
the "if (!NILP (handler))"-part. What is the !NILP (handler)-stuff?
and is the call2 and call3 appropriate? The later is taken verbatim
from GNU that has the same construction. (But it feel bad not knowing
a thing about what is going on ;-)
Your // Mats
----------------------------------------------------------------------
diff -r ec3712ffd0e6 src/dired.c
--- a/src/dired.c Fri Mar 15 13:52:53 2013 -0600
+++ b/src/dired.c Sun Mar 31 14:41:30 2013 +0200
@@ -820,14 +820,21 @@
}
#endif
-DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
+DEFUN ("file-attributes", Ffile_attributes, 1, 2, 0, /*
Return a list of attributes of file FILENAME.
Value is nil if specified file cannot be opened.
+
+ID-FORMAT specifies the preferred format of attributes uid and gid (see
+below) - valid values are 'string and 'integer. The latter is the
+default, but we plan to change that, so you should specify a non-nil value
+for ID-FORMAT if you use the returned uid or gid.
+
Otherwise, list elements are:
0. t for directory, string (name linked to) for symbolic link, or nil.
1. Number of links to file.
- 2. File uid.
- 3. File gid.
+ 2. File uid as a string or a number. If a string value cannot be
+ looked up, a numeric value, either an integer or a float, is returned.
+ 3. File gid, likewise.
4. Last access time, as a list of two integers.
First integer has high-order 16 bits of time, second has low 16 bits.
5. Last modification time, likewise.
@@ -840,7 +847,7 @@
If file does not exist, returns nil.
*/
- (filename))
+ (filename, id_format))
{
/* This function can GC. GC checked 1997.06.04. */
Lisp_Object directory = Qnil;
@@ -849,6 +856,9 @@
Lisp_Object handler, mode, modestring = Qnil, size, gid;
struct gcpro gcpro1, gcpro2, gcpro3;
+ Lisp_Object uidInfo = Qnil;
+ Lisp_Object gidInfo = Qnil;
+
GCPRO3 (filename, directory, modestring);
filename = Fexpand_file_name (filename, Qnil);
@@ -858,7 +868,10 @@
if (!NILP (handler))
{
UNGCPRO;
- return call2 (handler, Qfile_attributes, filename);
+ if (NILP(id_format))
+ return call2 (handler, Qfile_attributes, filename);
+ else
+ return call3 (handler, Qfile_attributes, filename, id_format);
}
if (qxe_lstat (XSTRING_DATA (filename), &s) < 0)
@@ -925,11 +938,25 @@
gid = (s.st_gid != getegid ()) ? Qt : Qnil;
#endif /* BSD4_2 or BSD4_3 */
+ if (NILP(id_format) || EQ (id_format, Qinteger))
+ {
+ uidInfo = make_integer (s.st_uid);
+ gidInfo = make_integer (s.st_gid);
+ }
+ else
+ {
+ struct passwd *pw = qxe_getpwuid (s.st_uid);
+ struct group *gr = qxe_getgrgid (s.st_gid);
+
+ uidInfo = build_istring (pw ? (Ibyte *) pw->pw_name : NULL);
+ gidInfo = build_istring (gr ? (Ibyte *) gr->gr_name : NULL);
+ }
+
RETURN_UNGCPRO (listn (12,
mode,
make_integer (s.st_nlink),
- make_integer (s.st_uid),
- make_integer (s.st_gid),
+ uidInfo,
+ gidInfo,
make_time (s.st_atime),
make_time (s.st_mtime),
make_time (s.st_ctime),
diff -r ec3712ffd0e6 src/sysdep.c
--- a/src/sysdep.c Fri Mar 15 13:52:53 2013 -0600
+++ b/src/sysdep.c Sun Mar 31 14:41:30 2013 +0200
@@ -3127,6 +3127,13 @@
#endif /* WIN32_NATIVE */
}
+// TODO: WIN32 mapping
+struct group *
+qxe_getgrgid (gid_t gid)
+{
+ return getgrgid (gid);
+}
+
#ifndef WIN32_NATIVE
struct passwd *
diff -r ec3712ffd0e6 src/syspwd.h
--- a/src/syspwd.h Fri Mar 15 13:52:53 2013 -0600
+++ b/src/syspwd.h Sun Mar 31 14:41:30 2013 +0200
@@ -20,6 +20,7 @@
#ifndef WIN32_NATIVE
# include <pwd.h>
+# include <grp.h>
#else /* WIN32_NATIVE */
@@ -52,6 +53,7 @@
struct passwd *qxe_getpwnam (const Ibyte *name);
struct passwd *qxe_getpwuid (uid_t uid);
+struct group *qxe_getgrgid (gid_t gid);
struct passwd *qxe_getpwent (void);
#endif /* emacs */
diff -r ec3712ffd0e6 tests/automated/dired-tests.el
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/automated/dired-tests.el Sun Mar 31 14:41:30 2013 +0200
@@ -0,0 +1,53 @@
+;; Copyright (C) 2013 Free Software Foundation, Inc.
+
+;; Author: Mats Lidell <matsl(a)xemacs.org>
+;; Maintainer:
+;; Created: 2013
+;; Keywords: tests
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by the
+;; Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+;; for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs. If not, see <
http://www.gnu.org/licenses/>.
+
+;;; Synched up with: Not in FSF.
+
+;;; Commentary:
+
+;; Test tag support.
+;; See test-harness.el for instructions on how to run these tests.
+
+(require 'test-harness)
+
+(let* ((test-file-name (make-temp-file "dired-test"))
+ (attr (file-attributes test-file-name)))
+ (Assert (equal (nth 0 attr) nil))
+ (Assert (equal (nth 1 attr) 1))
+ (Assert (numberp (nth 2 attr)))
+ (Assert (equal (nth 2 attr) (user-uid)))
+ (Assert (numberp (nth 3 attr)))
+ (Assert (equal (nth 4 attr) (nth 5 attr)))
+ (Assert (equal (nth 4 attr) (nth 6 attr)))
+ (Assert (equal (nth 7 attr) 0)))
+
+;; Optional ID-FORMAT set -> uid and gid are strings
+(let* ((test-file-name (make-temp-file "dired-test"))
+ (attr (file-attributes test-file-name t)))
+ (Assert (equal (nth 0 attr) nil))
+ (Assert (equal (nth 1 attr) 1))
+ (Assert (stringp (nth 2 attr)))
+ (Assert (equal (nth 2 attr) (user-login-name)))
+ (Assert (stringp (nth 3 attr)))
+ (Assert (equal (nth 4 attr) (nth 5 attr)))
+ (Assert (equal (nth 4 attr) (nth 6 attr)))
+ (Assert (equal (nth 7 attr) 0)))
----------------------------------------------------------------------
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-patches