Ejemplo n.º 1
0
        public static void File(string file)
        {
            MountRepository.Create(file, MountContext.External, MountEntity.File);
            var mntFile = SetFilesPath(file);

            SetBind(mntFile, file);
        }
Ejemplo n.º 2
0
        public static void Dir(string directory)
        {
            MountRepository.Create(directory, MountContext.External, MountEntity.Directory);
            var mntDir = SetDirsPath(directory);

            Directory.CreateDirectory(directory);
            Directory.CreateDirectory(mntDir);
            SetBind(mntDir, directory);
        }
Ejemplo n.º 3
0
        public static void CheckCurrentStatus()
        {
            var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var t in directories)
            {
                var realPath = GetDirsPath(t);
                var mount    = MountRepository.Get(realPath);
                if (mount == null)
                {
                    MountRepository.Create(realPath, MountContext.External, MountEntity.Directory);
                }
                if (Directory.Exists(realPath))
                {
                    continue;
                }
                try {
                    Terminal.Terminal.Execute($"mkdir -p {t}");
                    Terminal.Terminal.Execute($"mkdir -p {realPath}");
                    Terminal.Terminal.Execute($"cp {t} {realPath}");
                }
                catch (Exception ex) {
                    ConsoleLogger.Warn(ex.Message);
                }
            }
            ConsoleLogger.Log("current directories status checked");

            var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var t in files)
            {
                var realPath = GetFilesPath(t);
                var mount    = MountRepository.Get(realPath);
                if (mount == null)
                {
                    MountRepository.Create(realPath, MountContext.External, MountEntity.File);
                }
                if (System.IO.File.Exists(realPath))
                {
                    continue;
                }
                try {
                    var path    = t.GetAllStringsButLast('/');
                    var mntPath = realPath.GetAllStringsButLast('/');
                    Terminal.Terminal.Execute($"mkdir -p {path}");
                    Terminal.Terminal.Execute($"mkdir -p {mntPath}");
                    Terminal.Terminal.Execute($"cp {t} {realPath}");
                }
                catch (Exception ex) {
                    ConsoleLogger.Warn(ex.Message);
                }
            }
            ConsoleLogger.Log("current files status checked");
        }
Ejemplo n.º 4
0
        public static void Check()
        {
            var mounts      = MountRepository.Get();
            var mountModels = mounts as MountModel[] ?? mounts.ToArray();

            if (!mountModels.Any())
            {
                return;
            }
            foreach (var t in mountModels)
            {
                ConsoleLogger.Log($"{t.Path}:");
                CheckMount(t.Path);
            }
        }
Ejemplo n.º 5
0
        private static void CheckMount(string directory)
        {
            var isMntd       = IsAlreadyMounted(directory);
            var mntDirectory = SetDirsPath(directory);
            var timestampNow = Timestamp.Now;

            DFP.Set(mntDirectory, timestampNow);
            DFP.Set(directory, timestampNow);
            var dirsTimestamp      = DFP.GetTimestamp(mntDirectory);
            var dirsDfp            = dirsTimestamp != null;
            var directoryTimestamp = DFP.GetTimestamp(directory);
            var directoryDfp       = directoryTimestamp != null;

            if (isMntd && directoryTimestamp == "unauthorizedaccessexception" && dirsTimestamp == "unauthorizedaccessexception")
            {
                MountRepository.SetAsMountedReadOnly(directory);
            }
            else if (isMntd && dirsDfp && directoryDfp)
            {
                if (dirsTimestamp == directoryTimestamp)
                {
                    MountRepository.SetAsMounted(directory, mntDirectory);
                }
                else
                {
                    MountRepository.SetAsDifferentMounted(directory);
                }
            }
            else if (isMntd == false && dirsDfp && directoryDfp == false)
            {
                MountRepository.SetAsNotMounted(directory);
            }
            else if (isMntd && dirsDfp == false && directoryDfp)
            {
                MountRepository.SetAsTmpMounted(directory);
            }
            else if (isMntd == false && dirsDfp == false && directoryDfp == false)
            {
                MountRepository.SetAsError(directory);
            }
            else
            {
                MountRepository.SetAsError(directory);
            }
            DFP.Delete(mntDirectory);
            DFP.Delete(directory);
        }
Ejemplo n.º 6
0
        public static void AllDirectories()
        {
            if (!MountRepository.Get().Any())
            {
                foreach (var t in DefaultWorkingDirectories)
                {
                    MountRepository.Create(t, MountContext.Core, MountEntity.Directory);
                }
            }
            ConsoleLogger.Log("stored mount info checked");

            CheckCurrentStatus();
            ConsoleLogger.Log("current mount status checked");

            var directoryMounts = MountRepository.Get().Where(m => m.MountEntity == MountEntity.Directory).ToArray();

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

            var fileMounts = MountRepository.Get().Where(m => m.MountEntity == MountEntity.File).ToArray();

            foreach (var t in fileMounts)
            {
                var file    = t.Path.Replace("\\", "");
                var mntFile = SetFilesPath(file);
                if (mntFile == null)
                {
                    throw new ArgumentNullException(nameof(mntFile));
                }
                if (!System.IO.File.Exists(mntFile))
                {
                    continue;
                }
                var path    = file.GetAllStringsButLast('/');
                var mntPath = mntFile.GetAllStringsButLast('/');
                Terminal.Terminal.Execute($"mkdir -p {path}");
                Terminal.Terminal.Execute($"mkdir -p {mntPath}");
                if (!System.IO.File.Exists(file))
                {
                    Terminal.Terminal.Execute($"cp {mntFile} {file}");
                }
                ConsoleLogger.Log($"{mntFile} -> {file}");
                if (IsAlreadyMounted(file) == false)
                {
                    SetBind(mntFile, file);
                }
            }
            ConsoleLogger.Log("files mounted");

            foreach (var t in directoryMounts)
            {
                CheckMount(t.Path);
            }
            ConsoleLogger.Log("detected directories status checked");

            foreach (var srvc in from t in directoryMounts select t.AssociatedUnits into service where service.Count > 0 from srvc in service select srvc)
            {
                Terminal.Terminal.Execute($"systemctl restart {srvc}");
            }
            ConsoleLogger.Log("services restarted");
        }
Ejemplo n.º 7
0
        public static string GetBindMount(string path)
        {
            var mnt = MountRepository.Get(path);

            return(mnt.MountedPath.Length > 0 ? mnt.MountedPath : null);
        }