[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

updated [PATCH] [Issue 870] import should set svn:executable automatically

From: Brian Denny <brian_at_briandenny.net>
Date: 2002-09-27 06:49:26 CEST

This version of the patch incorporates several of the ideas/requests
put forth on this list.

Tests are still absent. (Working on it; have some specific questions
which will go in a separate e-mail).

Also, I haven't exercised this code on Windows as I am not yet set up
to build there. What it *should* do on Windows is: nothing different
from before (i.e., do not set svn:executable automatically).

-brian

Addresses issue 870: on import (and add), sets the svn:executable property
of files according to whether the file is actually executable by the
current user.

Thanks to the many people who contributed suggestions for this patch.

* subversion/include/svn_io.h : add header for new function
* subversion/libsvn_subr/io.c : add function 'svn_io_is_file_executable'
* subversion/libsvn_client/commit.c
  (import_file) : Check if file to be imported is executable;
                  if so, set svn:executable property.
* subversion/libsvn_wc/adm_ops.c
  (svn_wc_add) : Check if file to be added is executable;
                 if so, set svn:executable property.
                 Jeff Bellegarde suggested checking on add.

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h
+++ subversion/include/svn_io.h Thu Sep 26 21:48:06 2002
@@ -193,6 +193,16 @@
                                          svn_boolean_t ignore_enoent,
                                          apr_pool_t *pool);

+/* Determine whether a file is executable by the current user.
+ * Set *EXECUTABLE to TRUE if the file PATH is executable by the
+ * current user, otherwise set it to FALSE.
+ *
+ * On Windows and on platforms without userids, always returns FALSE.
+ */
+svn_error_t *svn_io_is_file_executable(svn_boolean_t *executable,
+ const char *path,
+ apr_pool_t *pool);
+

 /* Read a line from FILE into BUF, but not exceeding *LIMIT bytes.
  * Does not include newline, instead '\0' is put there.
Index: subversion/libsvn_wc/adm_ops.c
===================================================================
--- subversion/libsvn_wc/adm_ops.c
+++ subversion/libsvn_wc/adm_ops.c Thu Sep 26 21:30:03 2002
@@ -722,6 +722,7 @@
   enum svn_node_kind kind;
   apr_uint32_t modify_flags = 0;
   const char *mimetype = NULL;
+ svn_boolean_t executable = FALSE;
   svn_error_t *err;
   svn_wc_adm_access_t *adm_access;

@@ -838,6 +839,17 @@
           mt_str.data = mimetype;
           mt_str.len = strlen(mimetype);
           SVN_ERR (svn_wc_prop_set (SVN_PROP_MIME_TYPE, &mt_str, path,
+ parent_access, pool));
+ }
+
+ /* Set svn:executable if the new addition is executable. */
+ SVN_ERR (svn_io_is_file_executable (&executable, path, pool));
+ if (executable)
+ {
+ svn_string_t emptystr;
+ emptystr.data = "";
+ emptystr.len = 0;
+ SVN_ERR (svn_wc_prop_set (SVN_PROP_EXECUTABLE, &emptystr, path,
                                     parent_access, pool));
         }
     }
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c
+++ subversion/libsvn_subr/io.c Thu Sep 26 21:29:31 2002
@@ -641,6 +641,51 @@
 }

+svn_error_t *
+svn_io_is_file_executable(svn_boolean_t *executable,
+ const char *path,
+ apr_pool_t *pool)
+{
+#ifdef APR_HAS_USER
+#ifndef SVN_WIN32
+ apr_finfo_t file_info;
+ apr_status_t apr_err;
+ apr_uid_t uid;
+ apr_gid_t gid;
+ svn_boolean_t is_user;
+ svn_boolean_t is_group;
+#endif
+#endif
+
+ *executable = FALSE;
+
+#ifdef APR_HAS_USER
+#ifndef SVN_WIN32
+ /* Get file and user info. */
+ SVN_ERR (svn_io_stat (&file_info, path,
+ (APR_FINFO_PROT | APR_FINFO_OWNER),
+ pool));
+ apr_err = apr_current_userid (&uid, &gid, pool);
+
+ if (apr_err)
+ return svn_error_create(apr_err, 0, NULL, pool,
+ "Error getting UID of process.");
+
+ /* Check executable bit for current user. */
+ if (apr_compare_users(uid, file_info.user) == APR_SUCCESS)
+ *executable = (file_info.protection & APR_UEXECUTE);
+
+ else if (apr_compare_groups(gid, file_info.group) == APR_SUCCESS)
+ *executable = (file_info.protection & APR_GEXECUTE);
+
+ else
+ *executable = (file_info.protection & APR_WEXECUTE);
+#endif
+#endif
+ return SVN_NO_ERROR;
+}
+
+

 /*** Generic streams. ***/
Index: subversion/libsvn_client/commit.c
===================================================================
--- subversion/libsvn_client/commit.c
+++ subversion/libsvn_client/commit.c Wed Sep 25 19:14:01 2002
@@ -112,6 +112,7 @@
   apr_pool_t *subpool = svn_pool_create (hash_pool);
   const char *filepath = apr_pstrdup (hash_pool, path);
   struct imported_file *value = apr_palloc (hash_pool, sizeof (*value));
+ svn_boolean_t executable;

   /* Add the file, using the pool from the FILES hash. */
   SVN_ERR (editor->add_file (edit_path, dir_baton, NULL, SVN_INVALID_REVNUM,
@@ -123,6 +124,13 @@
   if (mimetype)
     SVN_ERR (editor->change_file_prop (file_baton, SVN_PROP_MIME_TYPE,
                                        svn_string_create (mimetype, pool),
+ pool));
+
+ /* If the file is executable, add that as a property to the file. */
+ SVN_ERR (svn_io_is_file_executable (&executable, path, pool));
+ if (executable)
+ SVN_ERR (editor->change_file_prop (file_baton, SVN_PROP_EXECUTABLE,
+ svn_string_create ("", pool),
                                        pool));

   if (notify_func)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Sep 27 06:53:43 2002

This is an archived mail posted to the Subversion Dev mailing list.