pytagsfs team mailing list archive
-
pytagsfs team
-
Mailing list archive
-
Message #00078
Re: xattr metastore: an initial attempt
On Sun, Jul 03, 2011 at 02:56:35PM -0400, Forest Bond wrote:
> Hi Raph,
>
> On Wed, Jun 22, 2011 at 01:32:37PM +0200, Raphaël Droz wrote:
> > On Sat, Jun 04, 2011 at 04:20:19PM -0400, Forest Bond wrote:
> > > The pytags utility was a bit of a hack and was written specifically for mutagen
> > > rather than as a general front end to the pytagsfs MetaStore API. We have
> > > changed this, so now it supports arbitrary metastores.
> > you're right, pytags now works and XattrMetaStore is cleaner !
>
> Yes, your implementation is looking pretty good now. If you clean things up a
> bit I can include this.
Attached the code in it simplest form.
(also attached to #742649)
> Maybe this should be a command-line option. Currently directories disappear
> when they are emptied, but I can see that either behavior might be
> desirable.
If you can point be to the right part of the code I would be happy to
provide such a patch if I can (for the "rm <file>" implementation too).
> > $ I can NOT add a new tag to a file (explanation below on how it is
> > different than above):
> > $ mkdir nuclear && cp ecology/Nuclear_wastes.avi nuclear/
> > cp: cannot create regular file `nuclear/Nuclear_wastes.avi': Function not implemented
> > [ attached as attempt1.log ]
> > Consequence is that the following obviously does NOT work:
> > $ mkdir waste && cp -a ecology waste
> > `ecology' -> `waste'
> > `ecology/Nuclear_wastes.avi' -> `waste/Nuclear_wastes.avi'
> > cp: cannot create regular file `waste/Nuclear_wastes.avi': Function not implemented
> > cp: failed to preserve ownership for `waste': Bad address
> > # Also note that the same also applies with a "simple" cp -r.
>
> Right, we can't support this via file copying because copying just creates a new
> file with the same data as the existing file and the filesystem is never told
> where the data comes from (i.e. the existing file's path). This could be
> supported with hard links, though. I think that would be a very natural way to
> add new tags to files.
The last example above was misleading, I meant:
$ cp -a ecology waste
# admitting "ecology" is either not an existing tag in the mounted
# filesystem, either it was filtered with "dstfilter".
In such case I would expected that every file tagged "ecology" would get
the "waste" tag added. But if, sadly, fuse does not provide the necessary
information I don't have opinion about available workarounds.
Raph
# coding: utf-8
# Copyright (c) 2011 Raphaël Droz.
# This file is part of the pytagsfs software package.
#
# pytagsfs is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2 as published by the Free
# Software Foundation.
#
# A copy of the license has been included in the COPYING file.
import xattr
from pytagsfs.metastore import MetaStore
from pytagsfs.values import Values
class XattrMetaStore(MetaStore):
def get(self, path):
d = dict ( xattr.get_all(path, namespace=xattr.NS_USER ) )
for k in d:
d[k] = d[k].split(',')
values = Values(d)
return values
def set(self, path, values):
for k,v in values.iteritems():
xattr.set(path, k, ','.join(v), namespace=xattr.NS_USER)
return values.keys()
Follow ups
References