From 7f90665936576dd4b0bc319b26c5d4e0a53a872e Mon Sep 17 00:00:00 2001 From: dbera Date: Fri, 4 Aug 2006 07:42:29 +0000 Subject: [PATCH] For writable files, if previously attributes were stored in sqlite db, remove it from there and store it now as xattr. --- Util/FileSystem.cs | 15 +++++++++++++++ beagled/FileAttributesStore_Mixed.cs | 24 +++++++++++++++++++----- beagled/LuceneFileQueryable.cs | 4 ++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Util/FileSystem.cs b/Util/FileSystem.cs index f6edae2c..9e0bd179 100644 --- a/Util/FileSystem.cs +++ b/Util/FileSystem.cs @@ -82,6 +82,21 @@ namespace Beagle.Util { return false; } + public static bool IsWritable (string path) + { + Mono.Unix.Native.Stat stat; + Mono.Unix.Native.Syscall.lstat (path, out stat); + + Mono.Unix.Native.FilePermissions type = (stat.st_mode & Mono.Unix.Native.FilePermissions.S_IFMT); + + if (type == Mono.Unix.Native.FilePermissions.S_IWUSR + || type == Mono.Unix.Native.FilePermissions.S_IWGRP + || type == Mono.Unix.Native.FilePermissions.S_IWOTH) + return true; + + return false; + } + // Special version of this function which handles the root directory. static public string GetDirectoryNameRootOk (string path) { diff --git a/beagled/FileAttributesStore_Mixed.cs b/beagled/FileAttributesStore_Mixed.cs index 663f9154..b9d13e60 100644 --- a/beagled/FileAttributesStore_Mixed.cs +++ b/beagled/FileAttributesStore_Mixed.cs @@ -25,6 +25,7 @@ // using System; +using Beagle.Util; namespace Beagle.Daemon { @@ -43,16 +44,29 @@ namespace Beagle.Daemon { // EA nightmare scenario: a file whose permissions or ownership get // changed after the EAs have been attached. Thus attributes in // the database always trump those found in EAs. - // - // FIXME: If we have write access to the path but it has attributes - // stored in the sqlite file attributes db, we should attach them - // to the file with EAs and delete the record from the db. public FileAttributes Read (string path) { FileAttributes attr; attr = store_sqlite.Read (path); - if (attr == null) + + if (attr!= null) { + // If we have write access to the path but it has attributes + // stored in the sqlite file attributes db, we should attach them + // to the file with EAs and delete the record from the db. + // Check if we have write access ? + if (! FileSystem.IsWritable (path)) + return attr; + + // What are the other cases when writing an xattr would fail ? + // FIXME: Should also check if extended attributes is supported ? + // Can that be done without incurring much cost, in which case + // we may try to write it anyway ? + + bool success = store_ea.Write (attr); + if (success) + store_sqlite.Drop (path); + } else attr = store_ea.Read (path); return attr; } diff --git a/beagled/LuceneFileQueryable.cs b/beagled/LuceneFileQueryable.cs index de4b6fe8..4971ed8c 100644 --- a/beagled/LuceneFileQueryable.cs +++ b/beagled/LuceneFileQueryable.cs @@ -26,8 +26,8 @@ // // This queryable just takes the LuceneQueryable and adds some sane -// default behavior for indexing files. -// +// default behavior for indexing files containing multiple indexables. +// Suitable for feedfiles or mbox style mail files. using System; using System.Collections; -- 2.11.4.GIT