util.copyfile and permissions

Matt Mackall mpm at selenic.com
Thu Oct 22 04:09:54 UTC 2009


On Wed, 2009-10-21 at 19:58 -0700, Chad Dombrova wrote:
> >> this function ensures that the access time and modification time of
> >> the destination file matches that of the source file.  where within
> >> the repo is this required and where not?
> >
> > Mercurial assumes it has full read/write access to everything in
> > the .hg/ directory. If that fails, things won't go well for you.
> > The usual way to deal with this on Unix is with groups and g+rwxs  
> > modes
> > on the .hg directory and subdirectories. The kernel will take care of
> > setting the group on those directories, and Mercurial will take care  
> > of
> > the r/w permission inheritance.
> 
> even with permissions set fully open -- rwx by user/group/other -- it  
> is not possible to explicitly set the time of a file that you do not  
> own.
> 
> from http://www.gnu.org/software/coreutils/manual/html_node/touch-invocation.html:
> "If changing both the access and modification times to the current  
> time, touch can change the timestamps for files that the user running  
> it does not own but has write permission for. Otherwise, the user must  
> own the files."
> 
> in the case of bookmarks i was wondering if there is some technical  
> reason that util.copyfile is used instead of shutil.copyfile, which  
> does not attempt to set timestamps.  i'm curious what the purpose of  
> setting these timestamps is.  i can see how it would be useful for  
> files in the working copy in order to avoid flagging them as modified,  
> but for internal files, it is less clear.  this question is in part a  
> warning:  if this function is used throughout mercurial as a basic  
> copy utility, then it could have pretty serious and unnecessary side  
> effects:  a shared repository that can only be safely used by one user  
> will probably not be widely useful.

We actually don't care about times on files at all. But we do care about
permissions, hence the use of shutil.copystat. But all we really care
about is matching the permissions on .hg/, so we can probably bypass the
chmod/utime calls entirely.

-- 
http://selenic.com : development and support for Mercurial and Linux





More information about the Mercurial mailing list