cvsimport
[beagle.git] / beagled / FileAttributesStore_Mixed.cs
blobb9d13e6020825497f233d5a282bfeb567c45831a
1 //
2 // FileAttributesStore_Mixed.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
27 using System;
28 using Beagle.Util;
30 namespace Beagle.Daemon {
32 public class FileAttributesStore_Mixed : IFileAttributesStore {
34 FileAttributesStore_ExtendedAttribute store_ea;
35 FileAttributesStore_Sqlite store_sqlite;
37 public FileAttributesStore_Mixed (string directory, string index_fingerprint)
39 store_ea = new FileAttributesStore_ExtendedAttribute (index_fingerprint);
40 store_sqlite = new FileAttributesStore_Sqlite (directory, index_fingerprint);
43 // We always have to query the Sqlite store first, because of our
44 // EA nightmare scenario: a file whose permissions or ownership get
45 // changed after the EAs have been attached. Thus attributes in
46 // the database always trump those found in EAs.
48 public FileAttributes Read (string path)
50 FileAttributes attr;
51 attr = store_sqlite.Read (path);
53 if (attr!= null) {
54 // If we have write access to the path but it has attributes
55 // stored in the sqlite file attributes db, we should attach them
56 // to the file with EAs and delete the record from the db.
57 // Check if we have write access ?
58 if (! FileSystem.IsWritable (path))
59 return attr;
61 // What are the other cases when writing an xattr would fail ?
62 // FIXME: Should also check if extended attributes is supported ?
63 // Can that be done without incurring much cost, in which case
64 // we may try to write it anyway ?
66 bool success = store_ea.Write (attr);
67 if (success)
68 store_sqlite.Drop (path);
69 } else
70 attr = store_ea.Read (path);
71 return attr;
74 public bool Write (FileAttributes attr)
76 return store_ea.Write (attr) || store_sqlite.Write (attr);
79 public void Drop (string path)
81 store_ea.Drop (path);
82 store_sqlite.Drop (path);
85 // Transactions do nothing for the EA store, so there is no
86 // point in calling it BeginTransaction or CommitTransaction
87 // on store_ea.
89 public void BeginTransaction ()
91 store_sqlite.BeginTransaction ();
94 public void CommitTransaction ()
96 store_sqlite.CommitTransaction ();