Posix File Info



I've added support for discovery of Owner, Group and File attributes of
an IndexableFile. The code uses the Mono.Posix class.

I've attached a patch and the file PosixFileInfo.cs, which should be
placed in the Util/ subfolder.

--Matt Jones
//
// PosixFileInfo.cs
//
// Copyright (C) 2004 Matthew Jones <mattharrison sbcglobal net>
//

//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

using Mono.Posix;

namespace Beagle.Util {

	public class PosixFileInfo {
		Stat filestats;

		public PosixFileInfo (string filename) {
			Syscall.stat (filename, out filestats);
		}

		public string GetOwnerName () {
			return Syscall.getusername (filestats.Uid);
		} 

		public string GetGroupName () {
			return Syscall.getgroupname (filestats.Gid);
		}

		public string GetMode () {
			int owner, group, other;
			owner = 0;
			group = 0;
			other = 0;

			if ((filestats.Mode & Mono.Posix.StatMode.OwnerRead) != 0)
				owner += 4;
			if ((filestats.Mode & Mono.Posix.StatMode.OwnerWrite) != 0)
				owner += 2;
			if ((filestats.Mode & Mono.Posix.StatMode.OwnerExecute) != 0)
				owner += 1;
			
			if ((filestats.Mode & Mono.Posix.StatMode.GroupRead) != 0)
				group += 4;
			if ((filestats.Mode & Mono.Posix.StatMode.GroupWrite) != 0)
				group += 2;
			if ((filestats.Mode & Mono.Posix.StatMode.GroupExecute) != 0)
				group += 1;

			if ((filestats.Mode & Mono.Posix.StatMode.OthersRead) != 0)
				other += 4;
			if ((filestats.Mode & Mono.Posix.StatMode.OthersWrite) != 0)
				other += 2;
			if ((filestats.Mode & Mono.Posix.StatMode.OthersExecute) != 0)
				other += 1;

			return (owner * 100 + group * 10 + other).ToString();
		}
	}
}
Index: indexer/IndexableFile.cs
===================================================================
RCS file: /cvs/gnome/beagle/indexer/IndexableFile.cs,v
retrieving revision 1.17
diff -u -r1.17 IndexableFile.cs
--- indexer/IndexableFile.cs	31 Jul 2004 21:51:44 -0000	1.17
+++ indexer/IndexableFile.cs	16 Aug 2004 20:59:09 -0000
@@ -88,6 +88,12 @@
 				parentName = info.DirectoryName;
 			}
 
+			BU.PosixFileInfo posixinfo = new BU.PosixFileInfo (path);
+
+			properties.Add (Property.NewKeyword ("fixme:ownername", posixinfo.GetOwnerName ()));
+			properties.Add (Property.NewKeyword ("fixme:groupname", posixinfo.GetGroupName ()));
+			properties.Add (Property.NewKeyword ("fixme:mode", posixinfo.GetMode()));
+
 			if (dirName != null)
 				properties.Add (Property.NewKeyword ("fixme:directory", dirName));
 
Index: Util/Makefile.am
===================================================================
RCS file: /cvs/gnome/beagle/Util/Makefile.am,v
retrieving revision 1.15
diff -u -r1.15 Makefile.am
--- Util/Makefile.am	1 Aug 2004 00:21:11 -0000	1.15
+++ Util/Makefile.am	16 Aug 2004 20:59:09 -0000
@@ -19,16 +19,19 @@
 	$(srcdir)/MultiReader.cs	\
 	$(srcdir)/NautilusTools.cs	\
 	$(srcdir)/PullingReader.cs	\
+	$(srcdir)/PosixFileInfo.cs	\
 	$(srcdir)/StringFu.cs
 
 ASSEMBLIES =				\
 	$(BEAGLE_UI_LIBS)		\
 	-r:System.Web.Services		\
-	-r:Mono.Data.SqliteClient
+	-r:Mono.Data.SqliteClient	\
+	-r:Mono.Posix
 
 
 $(TARGET): $(CSFILES) $(GOOGLE_CS)
Index: Tiles/template-file.html
===================================================================
RCS file: /cvs/gnome/beagle/Tiles/template-file.html,v
retrieving revision 1.3
diff -u -r1.3 template-file.html
--- Tiles/template-file.html	24 Jul 2004 21:57:45 -0000	1.3
+++ Tiles/template-file.html	16 Aug 2004 20:59:10 -0000
@@ -8,6 +8,7 @@
 <font size="1">
 @fixme:PageCount@ Pages,&nbsp; <!-- FIXME: wrong is _PageCount == 1 -->
 @fixme:Length@<br>
+Owner: @fixme:ownername@<br>
 Modified: @LastWriteTime@
 </font>
 </td>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]