Upload umask decorator

Lukas Zapletal lukas91 at zapletalovi.com
Fri Mar 13 09:27:59 GMT 2009


>     Lukas> It would be nice to have this feature in the
>     Lukas> authorization.conf - something like default_perms. It
>     Lukas> could be used by users in such situations described
>     Lukas> above.
> 
>     vila> Given that we need support from the server side to reliably
>     vila> implement that, authentication.conf sounds like the right
>     vila> place (locations.conf and branch.conf being more targeted at
>     vila> the local side of things).
> 
>     vila> On the other hand, finding the right place to acquire that
>     vila> setting may not be obvious, the transport layer seems like the
>     vila> appropriate place to do that and a transport is indeed available
>     vila> in _find_creation_modes(), so that may work.
> 
> Have a look there, I don't think a decorator is the right approach, it's
> not even needed and will make using the feature more complicated.

Ok I will look into this code. The decorator is already written, it was 
fun to do this... Here is a static version...

Btw I have no clue how to enable the decorator... how to use it...

Heres the code - just for fun.

"""Implementation of Upmask that allows to modify mode of uploaded
files with UNIX-style umask.

"""

from bzrlib.transport import get_transport, Transport, Server

class UpmaskTransportDecorator(TransportDecorator):
     """
     """

     @classmethod
     def _get_url_prefix(self):
         """Readonly transport decorators are invoked via 'upmask+'"""
         return 'upmask+'

     def _newfile_mask(self):
         """Return mask for created file according to
         the user-defined setting (umask)."""
         return 0666 & (~ self._umask)

     def _newdir_mask(self):
         """Return mask for created directory according to
         the user-defined setting (umask)."""
         return 0777 & (~ self._umask)

     def append_file(self, relpath, f, mode=None):
         """See Transport.append_file()."""
         return self._decorated.append_file(relpath, f,
                 mode=self._newfile_mask(mode))

     def append_bytes(self, relpath, bytes, mode=None):
         """See Transport.append_bytes()."""
         return self._decorated.append_bytes(relpath, bytes,
                 mode=self._newfile_mask(mode))

     def mkdir(self, relpath, mode=None):
         """See Transport.mkdir()."""
         return self._decorated.mkdir(relpath, self._newdir_mask(mode))

     def open_write_stream(self, relpath, mode=None):
         """See Transport.open_write_stream."""
         return self._decorated.open_write_stream(relpath,
                 mode=self._newfile_mask(mode))

     def put_file(self, relpath, f, mode=None):
         """See Transport.put_file()."""
         return self._decorated.put_file(relpath, f, 
self._newfile_mask(mode))

     def put_bytes(self, relpath, bytes, mode=None):
         """See Transport.put_bytes()."""
         return self._decorated.put_bytes(relpath, bytes,
                 self._newfile_mask(mode))

-- 
Lukáš Zapletal
http://lukas.zapletalovi.com




More information about the bazaar mailing list