예제 #1
0
        public static List <MountModel> GetAll()
        {
            var list        = new List <MountModel>();
            var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var directory in directories)
            {
                var mo = new MountModel {
                    SystemPath   = MountHelper.GetDirsPath(Path.GetFileName(directory)),
                    RepoDirsPath = directory,
                    Context      = MountContext.External,
                    Entity       = MountEntity.Directory
                };
                list.Add(mo);
            }
            var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var file in files)
            {
                var mo = new MountModel {
                    SystemPath   = MountHelper.GetFilesPath(Path.GetFileName(file)),
                    RepoDirsPath = file,
                    Context      = MountContext.External,
                    Entity       = MountEntity.File
                };
                list.Add(mo);
            }
            return(list);
        }
예제 #2
0
        public static void AllDirectories()
        {
            var list        = new List <MountModel>();
            var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var directory in directories)
            {
                var mo = new MountModel {
                    SystemPath   = MountHelper.GetDirsPath(Path.GetFileName(directory)),
                    RepoDirsPath = directory,
                    Context      = MountContext.External,
                    Entity       = MountEntity.Directory
                };
                list.Add(mo);
            }
            var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var file in files)
            {
                var mo = new MountModel {
                    SystemPath   = MountHelper.GetFilesPath(Path.GetFileName(file)),
                    RepoDirsPath = file,
                    Context      = MountContext.External,
                    Entity       = MountEntity.File
                };
                list.Add(mo);
            }
            ConsoleLogger.Log("directories and files enumerated");

            var directoryMounts = list.Where(m => m.Entity == MountEntity.Directory).ToList();

            foreach (var directoryMount in directoryMounts)
            {
                try {
                    var dir    = directoryMount.SystemPath.Replace("\\", "");
                    var mntDir = directoryMount.RepoDirsPath;
                    if (MountHelper.IsAlreadyMounted(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                        Directory.CreateDirectory(mntDir);
                        SetBind(mntDir, dir);
                        ConsoleLogger.Log($"mount {mntDir} -> {dir}");
                    }
                }
                catch (Exception ex) {
                    ConsoleLogger.Warn(ex.Message);
                }
            }
            ConsoleLogger.Log("directories mounted");

            var fileMounts = list.Where(m => m.Entity == MountEntity.File).ToList();

            foreach (var fileMount in fileMounts)
            {
                var file    = fileMount.SystemPath.Replace("\\", "");
                var mntFile = fileMount.RepoDirsPath;
                if (System.IO.File.Exists(mntFile))
                {
                    var path    = Path.GetDirectoryName(file);
                    var mntPath = Path.GetDirectoryName(mntFile);
                    if (MountHelper.IsAlreadyMounted(file) == false)
                    {
                        Bash.Execute($"mkdir -p {path}", false);
                        Bash.Execute($"mkdir -p {mntPath}", false);
                        if (!System.IO.File.Exists(file))
                        {
                            Bash.Execute($"cp {mntFile} {file}", false);
                        }
                        SetBind(mntFile, file);
                        ConsoleLogger.Log($"mount {mntFile} -> {file}");
                    }
                }
            }
            ConsoleLogger.Log("files mounted");
        }