Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////

        // Scans PathFinder.SystemIndexesDir after available
        // system-wide indexes.
        static void LoadSystemIndexes()
        {
            if (!Directory.Exists(PathFinder.SystemIndexesDir))
            {
                return;
            }

            Logger.Log.Info("Loading system static indexes.");

            int count = 0;

            Queryable queryable;

            foreach (DirectoryInfo index_dir in new DirectoryInfo(PathFinder.SystemIndexesDir).GetDirectories())
            {
                if (!UseQueryable(index_dir.Name))
                {
                    continue;
                }

                queryable = StaticQueryable.LoadStaticQueryable(index_dir, QueryDomain.System);
                if (queryable != null)
                {
                    iqueryable_to_queryable [queryable.IQueryable] = queryable;
                    count++;
                }
            }

            Logger.Log.Info("Found {0} system-wide indexes.", count);
        }
Ejemplo n.º 2
0
        // Instantiates and loads a StaticQueryable from an index directory
        internal static Queryable LoadStaticQueryable(DirectoryInfo index_dir, QueryDomain query_domain)
        {
            StaticQueryable static_queryable = null;

            if (!index_dir.Exists)
            {
                return(null);
            }

            try {
                static_queryable = new StaticQueryable(index_dir.Name, index_dir.FullName, true);
            } catch (InvalidOperationException) {
                Logger.Log.Warn("Unable to create read-only index (likely due to index version mismatch): {0}", index_dir.FullName);
                return(null);
            } catch (Exception e) {
                Logger.Log.Error(e, "Caught exception while instantiating static queryable: {0}", index_dir.Name);
                return(null);
            }

            if (static_queryable == null)
            {
                return(null);
            }

            // Load StaticIndex.xml from index_dir.FullName/config
            string config_file_path = Path.Combine(index_dir.FullName, "StaticIndex.xml");
            Config static_index_config;

            try {
                static_index_config = Conf.LoadFrom(config_file_path);
                if (static_index_config == null)
                {
                    Log.Error("Unable to read config from {0}", config_file_path);
                    return(null);
                }
            } catch (Exception e) {
                Log.Error(e, "Caught exception while reading config from {0}", config_file_path);
                return(null);
            }

            string source = static_index_config.GetOption("Source", null);

            if (source == null)
            {
                Log.Error("Invalid config file: {0}", config_file_path);
                return(null);
            }

            QueryableFlavor flavor = new QueryableFlavor();

            flavor.Name   = source;
            flavor.Domain = query_domain;

            Queryable queryable = new Queryable(flavor, static_queryable);

            return(queryable);
        }
Ejemplo n.º 3
0
        private static ResponseMessage AddRemovableIndex(string path, string mnt_dir)
        {
            DirectoryInfo index_dir = new DirectoryInfo(StringFu.SanitizePath(path));

            if (!index_dir.Exists)
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("'{0}' does not exist.", path);
                return(msg);
            }

            // Allow late loading of mount dir ?
            mnt_dir = StringFu.SanitizePath(mnt_dir);
            if (!Directory.Exists(mnt_dir))
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("Mount directory '{0}' does not exist.", mnt_dir);
                return(msg);
            }

            if (removable_queryables.ContainsKey(path))
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Adding removable index failed";
                msg.Details      = String.Format("'{0}' already added.", path);
                return(msg);
            }

            Queryable removable_queryable = null;

            try {
                iqueryable_lock.AcquireWriterLock(System.Threading.Timeout.Infinite);
                removable_queryable = StaticQueryable.LoadRemovableQueryable(index_dir, mnt_dir);
            } finally {
                iqueryable_lock.ReleaseWriterLock();
            }

            if (removable_queryable == null)
            {
                return(new ErrorResponse("Adding removable index failed"));
            }

            iqueryable_to_queryable [removable_queryable.IQueryable] = removable_queryable;
            removable_queryables [path] = removable_queryable;

            RemovableIndexResponse resp = new RemovableIndexResponse();

            resp.Source = removable_queryable.Name;
            Log.Info("Adding removable index '{0}' from {1}", resp.Source, path);
            return(resp);
        }
Ejemplo n.º 4
0
        private static ResponseMessage RemoveRemovableIndex(string path, string mnt_dir)
        {
            if (!removable_queryables.ContainsKey(path))
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Removing removable-index failed";
                msg.Details      = String.Format("'{0}' was not added.", path);
                return(msg);
            }

            Queryable removable_queryable = removable_queryables [path];

            // Assert
            if (removable_queryable == null ||
                !(removable_queryable.IQueryable is StaticQueryable))
            {
                ErrorResponse msg = new ErrorResponse("Removing removable-index failed");
                return(msg);
            }

            StaticQueryable static_queryable = (StaticQueryable)removable_queryable.IQueryable;

            if (static_queryable.RemovableMountDir != mnt_dir)
            {
                ErrorResponse msg;
                msg = new ErrorResponse();
                msg.ErrorMessage = "Removing removable-index failed";
                msg.Details      = String.Format("No index mounted at {0}.", mnt_dir);
                return(msg);
            }

            static_queryable.Close();

            removable_queryables.Remove(path);

            try {
                iqueryable_lock.AcquireWriterLock(System.Threading.Timeout.Infinite);
                iqueryable_to_queryable [removable_queryable.IQueryable] = null;
                iqueryable_to_queryable.Remove(removable_queryable.IQueryable);
            } finally {
                iqueryable_lock.ReleaseWriterLock();
            }

            RemovableIndexResponse resp = new RemovableIndexResponse();

            resp.Source = removable_queryable.Name;
            Log.Info("Removed removable-index '{0}' at {1}", removable_queryable.Name, path);
            return(resp);
        }
Ejemplo n.º 5
0
		// Instantiates and loads a StaticQueryable from an index directory
		internal static Queryable LoadStaticQueryable (DirectoryInfo index_dir, QueryDomain query_domain)
		{
			StaticQueryable static_queryable = null;
			
			if (!index_dir.Exists)
				return null;
			
			try {
				static_queryable = new StaticQueryable (index_dir.Name, index_dir.FullName, true);
			} catch (InvalidOperationException) {
				Logger.Log.Warn ("Unable to create read-only index (likely due to index version mismatch): {0}", index_dir.FullName);
				return null;
			} catch (Exception e) {
				Logger.Log.Error (e, "Caught exception while instantiating static queryable: {0}", index_dir.Name);
				return null;
			}

			if (static_queryable == null)
				return null;

			// Load StaticIndex.xml from index_dir.FullName/config
			string config_file_path = Path.Combine (index_dir.FullName, "StaticIndex.xml");
			Config static_index_config;
			try {
				static_index_config = Conf.LoadFrom (config_file_path);
				if (static_index_config == null) {
					Log.Error ("Unable to read config from {0}", config_file_path);
					return null;
				}
			} catch (Exception e) {
				Log.Error (e, "Caught exception while reading config from {0}", config_file_path);
				return null;
			}

			string source = static_index_config.GetOption ("Source", null);
			if (source == null) {
				Log.Error ("Invalid config file: {0}", config_file_path);
				return null;
			}

			QueryableFlavor flavor = new QueryableFlavor ();
			flavor.Name = source;
			flavor.Domain = query_domain;

			Queryable queryable = new Queryable (flavor, static_queryable);
			return queryable;
		}
Ejemplo n.º 6
0
        // Scans configuration for user-specified index paths
        // to load StaticQueryables from.
        static void LoadStaticQueryables()
        {
            int count = 0;

            if (UseQueryable("static"))
            {
                Logger.Log.Info("Loading user-configured static indexes.");
                List <string[]> values = Conf.Daemon.GetListOptionValues(Conf.Names.StaticQueryables);
                if (values != null)
                {
                    foreach (string[] path in values)
                    {
                        static_queryables.Add(path [0]);
                    }
                }
            }

            Queryable queryable;

            foreach (string path in static_queryables)
            {
                DirectoryInfo index_dir = new DirectoryInfo(StringFu.SanitizePath(path));

                if (!index_dir.Exists)
                {
                    continue;
                }

                // FIXME: QueryDomain might be other than local
                queryable = StaticQueryable.LoadStaticQueryable(index_dir, QueryDomain.Local);
                if (queryable != null)
                {
                    iqueryable_to_queryable [queryable.IQueryable] = queryable;
                    count++;
                }
            }

            Logger.Log.Info("Found {0} user-configured static indexes..", count);

            static_queryables = null;
        }