You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Sander Striker <st...@apache.org> on 2002/04/13 09:25:29 UTC

RE: svn commit: rev 1694 - trunk/subversion/tests/clients/cmdline/svntest

Hi,

Apparently shutil.copytree() doesn't copy permissions
without applying umask.  I don't know if there is an
equivalent of 'cp -a' in shutil, so I choose the easy
way out.

Without this, every test over dav was failing as soon
as something needed to be written.  And, as I don't
want to adjust my umask settings... :)

Sander


> Author: striker
> Date: 2002-04-13 09:02 GMT
> New Revision: 1694
> 
> Modified:
>    trunk/subversion/tests/clients/cmdline/svntest/actions.py
> Log:
> * subversion/tests/clients/cmdline/svntest/actions.py
> 
>   (guarantee_greek_repository): Fix a permission problem.
> 
> 
> Modified: trunk/subversion/tests/clients/cmdline/svntest/actions.py
> ==============================================================================
> --- trunk/subversion/tests/clients/cmdline/svntest/actions.py	(original)
> +++ trunk/subversion/tests/clients/cmdline/svntest/actions.py	Sat Apr 13 04:02:54 2002
> @@ -90,6 +90,10 @@
>    if not os.path.exists(os.path.dirname(path)):
>      os.makedirs(os.path.dirname(path))
>    shutil.copytree(main.pristine_dir, path)
> +
> +  # make the repos world-writeable, for mod_dav_svn's sake.
> +  os.system('chmod -R a+rw ' + path)
> +    
>    if os.path.exists(main.current_repo_dir):
>      os.unlink(main.current_repo_dir)                              
>    os.symlink(os.path.basename(path), main.current_repo_dir)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: svn commit: rev 1694 - trunk/subversion/tests/clients/cmdline/svntest

Posted by Sander Striker <st...@apache.org>.
> From: Greg Stein [mailto:gstein@lyra.org]
> Sent: 15 April 2002 09:15

> Hmm. That change should not have had to go in. shutil.copytree() *does* try
> to copy the permission information. It calls os.chmod() to do so. (it also
> copies the timestamp)
> 
> Are you sure it wasn't copying the mode bits, and it is simply that the
> Apache process needed the a+rw ? i.e. your source files didn't have the
> right permissions?

The apache process needs the a+rw, there is a similar line in the
repos creation code in svntest/main.py:
  # make the repos world-writeable, for mod_dav_svn's sake.
  os.system('chmod -R a+rw ' + path)

The perms on the 'pristine repos' are rwxrwxrwx (for dirs, leave the x for files)
after that.

After the shutil.copytree() from the 'pristine repos' I see rwxr-xr-x in the copy,
presumably because my umask is 022(?).  It's quite clear that mod_dav_svn needs
w perms to the repos.  I'm running httpd as an unprivilidged user, so I need the
o+w part.
 
> Basically, I'm suspicious of this change. I'd tend to be at a -1 on it
> without knowing more about the source and destinations perms that you were
> trying to achieve.

See above.
 
> Cheers,
> -g

Sander
 
> On Sat, Apr 13, 2002 at 11:25:29AM +0200, Sander Striker wrote:
> > Hi,
> > 
> > Apparently shutil.copytree() doesn't copy permissions
> > without applying umask.  I don't know if there is an
> > equivalent of 'cp -a' in shutil, so I choose the easy
> > way out.
> > 
> > Without this, every test over dav was failing as soon
> > as something needed to be written.  And, as I don't
> > want to adjust my umask settings... :)
> > 
> > Sander


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 1694 - trunk/subversion/tests/clients/cmdline/svntest

Posted by Branko Čibej <br...@xbc.nu>.
Sander Striker wrote:

>
>PS. Would something like this work to recursively set perms?
>
>def relax_perms(dir):
>    "Recursively set the perms to be very relaxed."
>
>    mode = os.stat(dir)[ST_MODE]
>    os.chmod(dir, S_IMODE(mode) | 0022)
>
>    for path in os.listdir(dir):
>        pathname = '%s/%s' % (dir, path)
>        mode = os.stat(pathname)[ST_MODE]
>        if S_ISDIR(mode):
>            # It's a directory, recurse into it
>            relax_perms(pathname)
>        elif S_ISREG(mode):
>            # It's a file, set its perms
>            os.chmod(pathname, S_IMODE(mode) | 0022)
>
What you're looking for is os.path.walk, os.path.isdir, os.path.isfile, ...


-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: svn commit: rev 1694 - trunk/subversion/tests/clients/cmdline/svntest

Posted by Sander Striker <st...@apache.org>.
> From: Greg Stein [mailto:gstein@lyra.org]
> Sent: 15 April 2002 09:15

> Hmm. That change should not have had to go in. shutil.copytree() *does* try
> to copy the permission information. It calls os.chmod() to do so. (it also
> copies the timestamp)
> 
> Are you sure it wasn't copying the mode bits, and it is simply that the
> Apache process needed the a+rw ? i.e. your source files didn't have the
> right permissions?
> 
> Basically, I'm suspicious of this change. I'd tend to be at a -1 on it
> without knowing more about the source and destinations perms that you were
> trying to achieve.
> 
> Cheers,
> -g

Ok, some more testing and fiddling, first remove the lines I committed:

Index: ./subversion/tests/clients/cmdline/svntest/actions.py
===================================================================
--- ./subversion/tests/clients/cmdline/svntest/actions.py
+++ ./subversion/tests/clients/cmdline/svntest/actions.py       Mon Apr 15 13:06:14 2002
@@ -91,9 +91,6 @@
     os.makedirs(os.path.dirname(path))
   shutil.copytree(main.pristine_dir, path)

-  # make the repos world-writeable, for mod_dav_svn's sake.
-  os.system('chmod -R a+rw ' + path)
-
   if os.path.exists(main.current_repo_dir):
     os.unlink(main.current_repo_dir)
   os.symlink(os.path.basename(path), main.current_repo_dir)


Then add this patch to reset a restrictive umask setting:

Index: ./subversion/tests/clients/cmdline/svntest/main.py
===================================================================
--- ./subversion/tests/clients/cmdline/svntest/main.py
+++ ./subversion/tests/clients/cmdline/svntest/main.py  Mon Apr 15 12:55:33 2002
@@ -365,6 +365,8 @@
       except ValueError:
         pass

+  os.umask(0);
+
   exit_code = _internal_run_tests(test_list, testnum)

   # remove all scratchwork: the 'pristine' repository, greek tree, etc.

$ cd subversion/tests/clients/cmdline

Now, step through the code in guarantee_greek_repository.  We first create
a pristine repos.  This gets its perms set very relaxed by the obscure
'chmod' call.  This should be replaced by something more portable, but
it gives us this:


$ ls -lR local_tmp/repos
local_tmp/repos:
total 6
-rw-rw-rw-   1 striker  striker       376 Apr 15 13:57 README
drwxrwxrwx   2 striker  striker        48 Apr 15 13:57 conf
drwxrwxrwx   2 striker  striker        48 Apr 15 13:57 dav
drwxrwxrwx   2 striker  striker       376 Apr 15 13:57 db
drwxrwxrwx   2 striker  striker       232 Apr 15 13:57 hooks
drwxrwxrwx   2 striker  striker        72 Apr 15 13:57 locks

local_tmp/repos/conf:
total 0

local_tmp/repos/dav:
total 0

local_tmp/repos/db:
total 424
-rw-rw-rw-   1 striker  striker       328 Apr 15 13:57 DB_CONFIG
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 __db.001
-rw-rw-rw-   1 striker  striker    270336 Apr 15 13:57 __db.002
-rw-rw-rw-   1 striker  striker    327680 Apr 15 13:57 __db.003
-rw-rw-rw-   1 striker  striker    360448 Apr 15 13:57 __db.004
-rw-rw-rw-   1 striker  striker     16384 Apr 15 13:57 __db.005
-rw-rw-rw-   1 striker  striker     44369 Apr 15 13:57 log.0000000001
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 nodes
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 representations
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 revisions
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 strings
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:57 transactions

local_tmp/repos/hooks:
total 20
-rw-rw-rw-   1 striker  striker      1302 Apr 15 13:57 post-commit.tmpl
-rw-rw-rw-   1 striker  striker      1366 Apr 15 13:57 pre-commit.tmpl
-rw-rw-rw-   1 striker  striker        99 Apr 15 13:57 read-sentinels.tmpl
-rw-rw-rw-   1 striker  striker      1322 Apr 15 13:57 start-commit.tmpl
-rw-rw-rw-   1 striker  striker       101 Apr 15 13:57 write-sentinels.tmpl

local_tmp/repos/locks:
total 4
-rw-rw-rw-   1 striker  striker       460 Apr 15 13:57 db.lock


Then an import takes place giving us this:

$ ls -lR local_tmp/repos/
local_tmp/repos:
total 6
-rw-rw-rw-   1 striker  striker       376 Apr 15 13:58 README
drwxrwxrwx   2 striker  striker      1024 Apr 15 13:58 conf
drwxrwxrwx   2 striker  striker      1024 Apr 15 13:58 dav
drwxrwxrwx   2 striker  striker      1024 Apr 15 13:58 db
drwxrwxrwx   2 striker  striker      1024 Apr 15 13:58 hooks
drwxrwxrwx   2 striker  striker      1024 Apr 15 13:58 locks

local_tmp/repos/conf:
total 0

local_tmp/repos/dav:
total 8
-rwxr-xr-x   1 httpd    httpd       12288 Apr 15 13:58 activities

local_tmp/repos/db:
total 489
-rw-rw-rw-   1 striker  striker       328 Apr 15 13:58 DB_CONFIG
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 __db.001
-rw-rw-rw-   1 striker  striker    270336 Apr 15 13:58 __db.002
-rw-rw-rw-   1 striker  striker    327680 Apr 15 13:58 __db.003
-rw-rw-rw-   1 striker  striker    360448 Apr 15 13:58 __db.004
-rw-rw-rw-   1 striker  striker     16384 Apr 15 13:58 __db.005
-rw-rw-rw-   1 striker  striker    105388 Apr 15 13:58 log.0000000001
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 nodes
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 representations
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 revisions
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 strings
-rw-rw-rw-   1 striker  striker      8192 Apr 15 13:58 transactions

local_tmp/repos/hooks:
total 8
-rw-rw-rw-   1 striker  striker      1302 Apr 15 13:58 post-commit.tmpl
-rw-rw-rw-   1 striker  striker      1366 Apr 15 13:58 pre-commit.tmpl
-rw-rw-rw-   1 striker  striker        99 Apr 15 13:58 read-sentinels.tmpl
-rw-rw-rw-   1 striker  striker      1322 Apr 15 13:58 start-commit.tmpl
-rw-rw-rw-   1 striker  striker       101 Apr 15 13:58 write-sentinels.tmpl

local_tmp/repos/locks:
total 1
-rw-rw-rw-   1 striker  striker       460 Apr 15 13:58 db.lock


All seems fine.  Now, the pristine repos gets copied (using shutil.copytree).
All permissions copy fine now, but we see a different problem:

$ ls -lR repositories/basic_tests-3/dav/
repositories/basic_tests-3/dav:
total 12
-rwxr-xr-x   1 striker  striker     12288 Apr 15 13:59 activities

Ownership changed.  And since the perms on activities stay the same,
my httpd user doesn't have write access to that file anymore.
And this causes tests to fail for obvious reasons.

I would love to help out here, but my py-fu would only get me a very
pale belt.  Someone with a black belt that wasn't washed that many
times is very welcome to jump in ;)


Sander

PS. Would something like this work to recursively set perms?

def relax_perms(dir):
    "Recursively set the perms to be very relaxed."

    mode = os.stat(dir)[ST_MODE]
    os.chmod(dir, S_IMODE(mode) | 0022)

    for path in os.listdir(dir):
        pathname = '%s/%s' % (dir, path)
        mode = os.stat(pathname)[ST_MODE]
        if S_ISDIR(mode):
            # It's a directory, recurse into it
            relax_perms(pathname)
        elif S_ISREG(mode):
            # It's a file, set its perms
            os.chmod(pathname, S_IMODE(mode) | 0022)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 1694 - trunk/subversion/tests/clients/cmdline/svntest

Posted by Greg Stein <gs...@lyra.org>.
Hmm. That change should not have had to go in. shutil.copytree() *does* try
to copy the permission information. It calls os.chmod() to do so. (it also
copies the timestamp)

Are you sure it wasn't copying the mode bits, and it is simply that the
Apache process needed the a+rw ? i.e. your source files didn't have the
right permissions?

Basically, I'm suspicious of this change. I'd tend to be at a -1 on it
without knowing more about the source and destinations perms that you were
trying to achieve.

Cheers,
-g

On Sat, Apr 13, 2002 at 11:25:29AM +0200, Sander Striker wrote:
> Hi,
> 
> Apparently shutil.copytree() doesn't copy permissions
> without applying umask.  I don't know if there is an
> equivalent of 'cp -a' in shutil, so I choose the easy
> way out.
> 
> Without this, every test over dav was failing as soon
> as something needed to be written.  And, as I don't
> want to adjust my umask settings... :)
> 
> Sander
> 
> 
> > Author: striker
> > Date: 2002-04-13 09:02 GMT
> > New Revision: 1694
> > 
> > Modified:
> >    trunk/subversion/tests/clients/cmdline/svntest/actions.py
> > Log:
> > * subversion/tests/clients/cmdline/svntest/actions.py
> > 
> >   (guarantee_greek_repository): Fix a permission problem.
> > 
> > 
> > Modified: trunk/subversion/tests/clients/cmdline/svntest/actions.py
> > ==============================================================================
> > --- trunk/subversion/tests/clients/cmdline/svntest/actions.py	(original)
> > +++ trunk/subversion/tests/clients/cmdline/svntest/actions.py	Sat Apr 13 04:02:54 2002
> > @@ -90,6 +90,10 @@
> >    if not os.path.exists(os.path.dirname(path)):
> >      os.makedirs(os.path.dirname(path))
> >    shutil.copytree(main.pristine_dir, path)
> > +
> > +  # make the repos world-writeable, for mod_dav_svn's sake.
> > +  os.system('chmod -R a+rw ' + path)
> > +    
> >    if os.path.exists(main.current_repo_dir):
> >      os.unlink(main.current_repo_dir)                              
> >    os.symlink(os.path.basename(path), main.current_repo_dir)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org