Пример #1
0
        private FSTabRecord(string line)
        {
            var elems    = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int addition = 0;

            if (elems.Length == 5)
            {
                addition = 1;
            }
            if (elems.Length + addition != 6)
            {
                throw new ArgumentException($"Fstab line is in wrong format: {line}");
            }

            Id = new FSTabId(elems[0]);
            if (elems[1] != "none")
            {
                MountPath = new MountPath(elems[1]);
            }
            else
            {
                MountPath = null;
            }
            Filesystem = new Filesystem(elems[2]);
            Options    = addition == 1 ? "" : elems[3];
            Dump       = int.Parse(elems[4 - addition]);
            Pass       = int.Parse(elems[5 - addition]);
        }
Пример #2
0
 /// <summary>
 ///     Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>A hash code for the current <see cref="T:System.Object" />.</returns>
 public override int GetHashCode()
 {
     return((string.IsNullOrWhiteSpace(ImageFilePath) ? 0 : ImageFilePath.GetHashCode())
            ^ MountMode.GetHashCode()
            ^ (string.IsNullOrWhiteSpace(MountPath) ? 0 : MountPath.GetHashCode())
            ^ MountStatus.GetHashCode());
 }
Пример #3
0
 public bool Equals(BobDisk other)
 {
     return(other != null &&
            EqualityComparer <PhysicalId> .Default.Equals(PhysicalId, other.PhysicalId) &&
            MountPath.Equals(other.MountPath) &&
            EqualityComparer <BobPath> .Default.Equals(BobPath, other.BobPath));
 }
Пример #4
0
 public BobDisk(PhysicalId physicalId, MountPath mountPath, BobPath bobPath, string diskNameInBob)
 {
     PhysicalId    = physicalId ?? throw new ArgumentNullException(nameof(physicalId));
     MountPath     = mountPath;
     BobPath       = bobPath ?? throw new ArgumentNullException(nameof(bobPath));
     DiskNameInBob = diskNameInBob;
 }
Пример #5
0
 internal void LoadMapCycle(FileInfo path = null)
 {
     MapCyclePath = path ?? MountPath.CombineFile("mapcycle.txt");
     if (MapCyclePath.Exists)
     {
         MapCycle = MapCyclePath.ReadAllLines().Select(a => a.ToLower()).Where(arg => !string.IsNullOrWhiteSpace(arg)).ToList();
     }
 }
Пример #6
0
        /// <inheritdoc />
        public async Task StopMonitor(MountPath mountPath)
        {
            if (this.monitors.ContainsKey(mountPath.Id) && this.monitors.TryRemove(mountPath.MountId, out var proxy))
            {
                await proxy.Stop()
                .ConfigureAwait(false);

                proxy.Dispose();
            }
        }
Пример #7
0
        private static string GetNfsMountUrl(this MountPath source)
        {
            var credentials = source.Mount.Credentials;
            var userinfo    = string.Empty;

            if (credentials != null && credentials.Type == CredentialType.Basic)
            {
                userinfo = $"{credentials.Login}:{credentials.Password}@";
            }

            return($"nfs://{userinfo}{source.Mount.Host}/{source.Path}");
        }
Пример #8
0
        public static Uri GetMountUrl(this MountPath source)
        {
            switch (source.Mount.Type)
            {
            case MountType.Nfs:
                return(new Uri(source.GetNfsMountUrl()));

            case MountType.Smb:
                return(new Uri(source.GetSmbMountUrl()));

            default:
                return(new Uri(source.GetLocalMountUrl()));
            }
        }
Пример #9
0
        /// <inheritdoc />
        public Task StartMonitor(MountPath mountPath)
        {
            if (this.monitors.ContainsKey(mountPath.Id))
            {
                return(Task.CompletedTask);
            }

            var proxy = new FileSystemWatcherProxy(this.FileService, this.Logger, mountPath);

            if (this.monitors.TryAdd(mountPath.Id, proxy) == false)
            {
                throw new InvalidOperationException($"Failed to monitor mount: {mountPath.Id}");
            }

            return(proxy.Start());
        }
Пример #10
0
        /// <inheritdoc />
        public async Task <MountPath> CreateMountPath(Guid mountId, string filepath, CancellationToken cancellationToken = default)
        {
            var mount = await this.Context.Mounts.Include(m => m.Paths)
                        .SingleAsync(m => m.Id == mountId, cancellationToken)
                        .ConfigureAwait(false);

            if (mount.Paths.Any(mp => mp.Path == filepath))
            {
                throw new EntityExistsException <MountPath>(filepath);
            }

            var path = new MountPath
            {
                Path = filepath, Mount = mount,
            };

            mount.Paths.Add(path);

            await this.Context.SaveChangesAsync(cancellationToken)
            .ConfigureAwait(false);

            return(path);
        }
Пример #11
0
 public static Uri GetMountUri(this MountPath source)
 {
     return(source.GetMountUrl());
 }
Пример #12
0
 private static string GetSmbMountUrl(this MountPath source)
 {
     return($"file://{source.Mount.Host}{source.Path}");
 }
Пример #13
0
            public FileSystemWatcherProxy(IFileService fileService, ILogger <MonitorService> logger, MountPath mountPath)
            {
                this.FileService = fileService;
                this.Logger      = logger;
                this.MountPath   = mountPath;

                var uri = this.MountPath.GetMountUri();

                this.Monitor = new FileSystemWatcher
                {
                    IncludeSubdirectories = true, Path = uri.LocalPath,
                };

                this.Monitor.Changed += this.MonitorOnChanged;
                this.Monitor.Created += this.MonitorOnCreated;
                this.Monitor.Deleted += this.MonitorOnDeleted;
                this.Monitor.Renamed += this.MonitorOnRenamed;
            }
Пример #14
0
        private async Task <bool> TryCleanPreviousData(Volume volume, BobApiClient bobApiClient, MountPath path)
        {
            int count = 0;

            await TryStopBobdisk(volume, bobApiClient);

            while (count++ < configuration.MaxUmountRetries)
            {
                try
                {
                    var disks = await disksFinder.FindDisks();

                    if (disks.Any(d => d.Volumes.Count > 0 && d.Volumes.Any(v => v.MountPath?.Equals(path) == true && v.IsMounted)))
                    {
                        logger.LogInformation($"Trying to unmount previous disks in {path}");
                        await processInvoker.InvokeSudoProcess("umount", path.ToString());

                        logger.LogInformation($"Successfully umounted previous disks in {path}");
                    }
                    return(true);
                }
                catch (ProcessFailedException e) when(e.ExitCode == 32)
                {
                    await Task.Delay(1000);
                }
            }
Пример #15
0
 public bool StartsWith(MountPath path) => data.StartsWith(path.Path);
Пример #16
0
 /// <inheritdoc />
 public Task <IEnumerable <MountPathFile> > ImportFiles(MountPath mount, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }