Esempio n. 1
0
    static void ScanPath(UnixDirectoryInfo dirinfo, string prefix)
    {
        foreach (var fileinfo in dirinfo.GetFileSystemEntries())
        {
            string id = string.Concat(prefix, fileinfo.Name);
            switch (fileinfo.FileType)
            {
            case FileTypes.RegularFile:
                string hash;

                if (fileinfo.Length == 0)
                {
                    hash = "0\t0\t0\t0";
                }
                else
                {
                    hash = FormatMd5Hash(fileinfo.FullName);
                }

                Console.WriteLine("{0}\t0\t{1}", id, hash);
                break;

            case FileTypes.Directory:
                ScanPath((UnixDirectoryInfo)fileinfo, string.Concat(id, "!"));
                break;

            default:
                /* Do nothing for symlinks or other weird things. */
                break;
            }
        }
    }
Esempio n. 2
0
		public static Listing LoadFrom (string url, Comparison<FileNode> compare)
		{
			try {
				var udi = new UnixDirectoryInfo (url);
				return new Listing (url, udi.GetFileSystemEntries (), compare);
			} catch (Exception e){
				return new Listing ();
			}
			return null;
		}
Esempio n. 3
0
        public IEnumerable <string> GetFiles(string directory)
        {
            UnixDirectoryInfo unix_dir = new UnixDirectoryInfo(directory);

            foreach (UnixFileSystemInfo entry in unix_dir.GetFileSystemEntries())
            {
                if (!entry.IsDirectory && entry.IsRegularFile && !entry.IsSocket && entry.Exists)
                {
                    yield return(entry.FullName);
                }
            }
        }
Esempio n. 4
0
        public IEnumerable <SafeUri> GetDirectories(string directory)
        {
            var unix_dir = new UnixDirectoryInfo(directory);

            foreach (var entry in unix_dir.GetFileSystemEntries())
            {
                var info = TraverseSymlink(entry);
                if (info != null && info.IsDirectory && info.Exists && !info.IsSocket)
                {
                    yield return(new SafeUri(info.FullName, false));
                }
            }
        }
Esempio n. 5
0
		void LoadChild (int idx)
		{
			DirNode dn = this [idx] as DirNode;
			string name = GetName (idx, url, nodes);
				
			try {
				var udi = new UnixDirectoryInfo (name);
				dn.Nodes = PopulateNodes (true, udi.GetFileSystemEntries ());
				dn.Expanded = true;
			} catch (Exception e){
				Console.WriteLine ("Error loading {0}", name);
				// Show error?
				return;
			}
			Count = UpdateIndexes (nodes, 0, 0);
		}
        private void ScanPath(UnixDirectoryInfo dirinfo, PreingestEventArgs passEventArgs)
        {
            passEventArgs.Description = String.Format("Processing folder '{0}'.", dirinfo.FullName);
            OnTrigger(passEventArgs);
            dirinfo.FileAccessPermissions = FileAccessPermissions.AllPermissions;
            foreach (var fileinfo in dirinfo.GetFileSystemEntries())
            {
                switch (fileinfo.FileType)
                {
                case FileTypes.RegularFile:
                    fileinfo.FileAccessPermissions = FileAccessPermissions.AllPermissions;
                    break;

                case FileTypes.Directory:
                    ScanPath((UnixDirectoryInfo)fileinfo, passEventArgs);
                    break;

                default:
                    /* Do nothing for symlinks or other weird things. */
                    break;
                }
            }
        }
Esempio n. 7
0
File: main.cs Progetto: zofuthan/xsp
        public static int Main(string [] args)
        {
            var configurationManager = new ConfigurationManager("mono-fpm");

            if (!configurationManager.LoadCommandLineArgs(args))
            {
                return(1);
            }

            // Show the help and exit.
            if (configurationManager.Help)
            {
                configurationManager.PrintHelp();
#if DEBUG
                Console.WriteLine("Press any key...");
                Console.ReadKey();
#endif
                return(0);
            }

            // Show the version and exit.
            if (configurationManager.Version)
            {
                Version.Show();
                return(0);
            }

            if (!configurationManager.LoadConfigFile())
            {
                return(1);
            }

            configurationManager.SetupLogger();

#if DEBUG
            // Log everything while debugging
            Logger.Level = LogLevel.All;
#endif

            Logger.Write(LogLevel.Debug, Assembly.GetExecutingAssembly().GetName().Name);

            string configDir = configurationManager.ConfigDir;
            string webDir    = configurationManager.WebDir;
            if (String.IsNullOrEmpty(configDir) && (!Platform.IsUnix || String.IsNullOrEmpty(webDir)))
            {
                if (Platform.IsUnix)
                {
                    Logger.Write(LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter or web directories with the --web-dir parameter.");
                }
                else
                {
                    Logger.Write(LogLevel.Error, "You MUST provide a configuration directory with the --config-dir parameter.");
                }
                return(1);
            }

            if (!String.IsNullOrEmpty(configDir))
            {
                var configDirInfo = new DirectoryInfo(configDir);
                if (!configDirInfo.Exists)
                {
                    Logger.Write(LogLevel.Error, "The configuration directory \"{0}\" does not exist!", configDir);
                }
                else
                {
                    Logger.Write(LogLevel.Debug, "Configuration directory {0} exists, loading configuration files", configDir);

                    FileInfo[] configFiles = configDirInfo.GetFiles("*.xml");
                    ChildrenManager.StartChildren(configFiles, configurationManager);
                }
            }

            if (Platform.IsUnix && !String.IsNullOrEmpty(webDir))
            {
                var webDirInfo = new UnixDirectoryInfo(Path.GetFullPath(webDir));
                if (!webDirInfo.Exists)
                {
                    Logger.Write(LogLevel.Error, "The web directory \"{0}\" does not exist!", webDir);
                }
                else
                {
                    Logger.Write(LogLevel.Debug, "Web directory {0} exists, starting children", webDir);

                    IEnumerable <UnixDirectoryInfo> webDirs =
                        from entry in webDirInfo.GetFileSystemEntries()
                        let dir = entry as UnixDirectoryInfo
                                  where dir != null
                                  select dir;

                    if (configurationManager.HttpdGroup == null)
                    {
                        Logger.Write(LogLevel.Error, "Couldn't autodetect the httpd group, you must specify it explicitly with --httpd-group");
                        return(1);
                    }
                    if (!CheckGroupExists(configurationManager.FpmGroup) || !CheckGroupExists(configurationManager.HttpdGroup) || !CheckUserExists(configurationManager.FpmUser))
                    {
                        return(1);
                    }
                    ChildrenManager.StartAutomaticChildren(webDirs, configurationManager);
                }
            }

            Platform.SetIdentity(configurationManager.FpmUser, configurationManager.FpmGroup);

            if (!configurationManager.Stoppable)
            {
                var sleep = new ManualResetEvent(false);
                sleep.WaitOne();                  // Do androids dream of electric sheep?
            }

            Console.WriteLine("Hit Return to stop the server.");
            Console.ReadLine();

            ChildrenManager.TermChildren();
            ChildrenManager.KillChildren();
            return(0);
        }
Esempio n. 8
0
        Result CopyDirectory(string source_absolute_path, string target_path, FilePermissions protection)
        {
            if (!dirs_created.ContainsKey(target_path))
            {
                while (true)
                {
                    int r = Syscall.mkdir(target_path, protection | FilePermissions.S_IRWXU);
                    if (r != -1)
                    {
                        break;
                    }

                    Errno errno = Stdlib.GetLastError();
                    if (errno == Errno.EINTR)
                    {
                        continue;
                    }

                    if (errno == Errno.EEXIST || errno == Errno.EISDIR)
                    {
                        break;
                    }

                    var msg = UnixMarshal.GetErrorDescription(errno);
                    switch (Interaction.Query(OResult.RetryIgnoreCancel, msg, "While creating \"{0}\"", target_path))
                    {
                    case OResult.Retry:
                        continue;

                    case OResult.Ignore:
                        break;

                    case OResult.Cancel:
                        return(Result.Cancel);
                    }
                }
                dirs_created [target_path] = protection;
            }

            var udi = new UnixDirectoryInfo(source_absolute_path);

            foreach (var entry in udi.GetFileSystemEntries())
            {
                if (entry.Name == "." || entry.Name == "..")
                {
                    continue;
                }

                string source = Path.Combine(source_absolute_path, entry.Name);
                string target = Path.Combine(target_path, entry.Name);
                if (entry.IsDirectory)
                {
                    if (CopyDirectory(source, target, entry.Protection) == Result.Cancel)
                    {
                        return(Result.Cancel);
                    }
                }
                else
                {
                    if (!CopyFile(source, target))
                    {
                        return(skip ? Result.Skip : Result.Cancel);
                    }
                }
            }
            return(Result.Ok);
        }