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

[PATCH] Add svn:permissions support

From: Justin Erenkrantz <jerenkrantz_at_apache.org>
Date: 2002-08-21 08:02:48 CEST

As posted earlier, this patch allows file permissions to become a
property of the repository that the client can then respect.

local:
svn propset svn:permissions 600 <file>
svn ci

somewhere else:
svn co <repos-path>
*Poof, permissions are set on the working copy as specified.*

(Of course, on Win32 or other platforms, this would be a no-op.)

I'm happy and would love to see this make it into the main tree.
As it is, my tree is slowly coming out-of-sync with the trunk
as I have a lot of local changes. I should attempt to resync
with trunk if I get a chance (but I'm not sure how many of the
changes would be accepted by the rest of the group). -- justin

* subversion/include/svn_props.h:
  Add SVN_PROP_PERMISSIONS define.
* subversion/libsvn_wc/translate.h, subversion/libsvn_wc/translate.c:
  Add svn_wc__maybe_set_permissions
* subversion/include/svn_io.h, subversion/libsvn_subr/io.c:
  Add svn_io_set_file_permissions
* subversion/libsvn_wc/props.c (svn_wc_prop_set):
  If encounter SVN_PROP_PERMISSIONS, call svn_io_set_file_permissions.
* subversion/libsvn_wc/log.c (file_xfer_under_path, install_committed_file),
  subversion/libsvn_wc/adm_ops.c (revert_admin_things),
  subversion/libsvn_wc/merge.c (svn_wc_merge),
  subversion/libsvn_wc/adm_crawler.c (restore_file):
  Call svn_wc__maybe_set_permissions

Index: subversion/include/svn_props.h
===================================================================
--- subversion/include/svn_props.h
+++ subversion/include/svn_props.h Tue Aug 20 18:38:30 2002
@@ -126,6 +126,9 @@
 /* The character set of a given file. */
 #define SVN_PROP_CHARSET SVN_PROP_PREFIX "charset"
 
+/* Defines a numeric permissions mode of a given file. */
+#define SVN_PROP_PERMISSIONS SVN_PROP_PREFIX "permissions"
+
 /* --------------------------------------------------------------------- */
 /** INVISIBLE PROPERTIES **/
 
Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h
+++ subversion/include/svn_io.h Tue Aug 20 19:32:37 2002
@@ -193,6 +193,15 @@
                                          svn_boolean_t ignore_enoent,
                                          apr_pool_t *pool);
 
+/* Set a file's permissions, as much as the operating system
+ allows. PATH is the utf8-encoded path to the file. PERMS is the
+ string-encoded permissions. If IGNORE_ENOENT is TRUE, don't fail if
+ the target file doesn't exist. */
+svn_error_t *svn_io_set_file_permissions (const char *path,
+ const char *perms,
+ svn_boolean_t ignore_enoent,
+ 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/merge.c
===================================================================
--- subversion/libsvn_wc/merge.c
+++ subversion/libsvn_wc/merge.c Tue Aug 20 22:48:08 2002
@@ -332,7 +332,9 @@
     } /* end of binary conflict handling */
 
   /* Merging is complete. Regardless of text or binariness, we might
- need to tweak the executable bit on the new working file. */
+ need to tweak the permissions on the new working file. */
+ SVN_ERR (svn_wc__maybe_set_permissions (&toggled, merge_target, pool));
+
   SVN_ERR (svn_wc__maybe_toggle_working_executable_bit (&toggled,
                                                         merge_target, pool));
 
Index: subversion/libsvn_wc/translate.h
===================================================================
--- subversion/libsvn_wc/translate.h
+++ subversion/libsvn_wc/translate.h Tue Aug 20 22:46:38 2002
@@ -110,6 +110,14 @@
                                              const char *path,
                                              apr_pool_t *pool);
 
+/* If the SVN_PROP_PERMISSIONS property is present, then set PATH to the
+ right permissions. Set *TOGGLED to TRUE if this happened, or FALSE
+ if not. */
+svn_error_t *
+svn_wc__maybe_set_permissions (svn_boolean_t *toggled,
+ const char *path,
+ apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/libsvn_wc/props.c
===================================================================
--- subversion/libsvn_wc/props.c
+++ subversion/libsvn_wc/props.c Tue Aug 20 19:35:58 2002
@@ -1060,6 +1060,10 @@
     {
       SVN_ERR (svn_validate_mime_type (value->data, pool));
     }
+ else if ((strcmp (name, SVN_PROP_PERMISSIONS) == 0) && value)
+ {
+ SVN_ERR (svn_io_set_file_permissions (path, value->data, TRUE, pool));
+ }
 
   err = svn_wc_prop_list (&prophash, path, pool);
   if (err)
Index: subversion/libsvn_wc/adm_crawler.c
===================================================================
--- subversion/libsvn_wc/adm_crawler.c
+++ subversion/libsvn_wc/adm_crawler.c Tue Aug 20 22:46:46 2002
@@ -79,6 +79,9 @@
   
   SVN_ERR (svn_io_remove_file (tmp_text_base_path, pool));
 
+ /* If necessary, tweak the new working file's permissions bit. */
+ SVN_ERR (svn_wc__maybe_set_permissions (&toggled, file_path, pool));
+
   /* If necessary, tweak the new working file's executable bit. */
   SVN_ERR (svn_wc__maybe_toggle_working_executable_bit
            (&toggled, file_path, pool));
Index: subversion/libsvn_wc/log.c
===================================================================
--- subversion/libsvn_wc/log.c
+++ subversion/libsvn_wc/log.c Tue Aug 20 22:48:01 2002
@@ -118,7 +118,12 @@
                                             TRUE,
                                             pool));
 
- /* After copying, toggle the executable bit if props dictate. */
+ /* After copying, toggle the executable bit or permissions if props
+ * dictate.
+ */
+ SVN_ERR (svn_wc__maybe_set_permissions (&toggled, full_dest_path,
+ pool));
+
         return svn_wc__maybe_toggle_working_executable_bit
           (&toggled,
            full_dest_path,
@@ -265,6 +270,13 @@
     }
 
   SVN_ERR (svn_io_remove_file (tmp_wfile, pool));
+
+ /* Set the permissions if props dictate. */
+ SVN_ERR (svn_wc__maybe_set_permissions (&toggled, filepath, pool));
+ if (toggled)
+ /* okay, so we didn't -overwrite- the working file, but we changed
+ its timestamp, which is the point of returning this flag. :-) */
+ *overwrote_working = TRUE;
 
   /* Toggle the working file's execute bit if props dictate. */
   SVN_ERR (svn_wc__maybe_toggle_working_executable_bit (&toggled,
Index: subversion/libsvn_wc/adm_ops.c
===================================================================
--- subversion/libsvn_wc/adm_ops.c
+++ subversion/libsvn_wc/adm_ops.c Tue Aug 20 22:46:57 2002
@@ -1105,6 +1105,9 @@
                                                 pool)))
             return revert_error (err, fullpath, "restoring text", pool);
 
+ /* If necessary, set the new file's permissions. */
+ SVN_ERR (svn_wc__maybe_set_permissions (&toggled, fullpath, pool));
+
           /* If necessary, tweak the new working file's executable bit. */
           SVN_ERR (svn_wc__maybe_toggle_working_executable_bit
                    (&toggled, fullpath, pool));
Index: subversion/libsvn_wc/translate.c
===================================================================
--- subversion/libsvn_wc/translate.c
+++ subversion/libsvn_wc/translate.c Tue Aug 20 22:46:03 2002
@@ -1040,6 +1040,25 @@
   return SVN_NO_ERROR;
 }
 
+svn_error_t *
+svn_wc__maybe_set_permissions (svn_boolean_t *toggled,
+ const char *path,
+ apr_pool_t *pool)
+{
+ const svn_string_t *propval;
+ SVN_ERR (svn_wc_prop_get (&propval, SVN_PROP_PERMISSIONS, path, pool));
+
+ if (propval != NULL)
+ {
+ SVN_ERR (svn_io_set_file_permissions (path, propval->data, FALSE, pool));
+ *toggled = TRUE;
+ }
+ else {
+ *toggled = FALSE;
+ }
+
+ return SVN_NO_ERROR;
+}
 
 
 
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c
+++ subversion/libsvn_subr/io.c Tue Aug 20 22:24:28 2002
@@ -639,6 +639,36 @@
   return SVN_NO_ERROR;
 }
 
+svn_error_t *
+svn_io_set_file_permissions (const char *path,
+ const char *perms,
+ svn_boolean_t ignore_enoent,
+ apr_pool_t *pool)
+{
+ apr_status_t status;
+ const char *path_native;
+ apr_int64_t i;
+
+ SVN_ERR (svn_utf_cstring_from_utf8 (&path_native, path, pool));
+
+ /* APR's permissions flags are hex-equivalents of the octets. */
+ i = apr_strtoi64 (perms, NULL, 16);
+
+ /* This cast is probably safe since we're going from 64-bit to a
+ * 32-bit value.
+ */
+ status = apr_file_perms_set (path, (apr_fileperms_t) i);
+ if (status != APR_SUCCESS && !APR_STATUS_IS_INCOMPLETE(status) &&
+ !APR_STATUS_IS_ENOTIMPL(status) &&
+ (!ignore_enoent || !APR_STATUS_IS_ENOENT(status))) {
+ return svn_error_createf (status, 0, NULL, pool,
+ "svn_io_set_file_permissions: "
+ "failed to set permissions on %s (%s)",
+ path, perms);
+ }
+
+ return SVN_NO_ERROR;
+}
 
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Aug 21 08:03:28 2002

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.