IsUnixFS() public static method

Determines whether a directory resides on a non-Unix filesystem.
The flag file is searched for instead of specifiying it directly to allow handling of special cases like creating manifests of subdirectories of extracted archives.
public static IsUnixFS ( [ target ) : bool
target [ The full path to the directory.
return bool
Beispiel #1
0
        /// <summary>
        /// Creates a new directory walking task.
        /// </summary>
        /// <param name="sourceDirectory">The path of the directory to walk.</param>
        protected DirectoryWalkTask([NotNull] string sourceDirectory)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(sourceDirectory))
            {
                throw new ArgumentNullException(nameof(sourceDirectory));
            }
            #endregion

            SourceDirectory = new DirectoryInfo(Path.GetFullPath(sourceDirectory));
            _isUnixFS       = FlagUtils.IsUnixFS(sourceDirectory);
        }
Beispiel #2
0
        public void TestIsUnixFS()
        {
            using (var tempDir = new TemporaryDirectory("0install-unit-tests"))
            {
                if (UnixUtils.IsUnix)
                {
                    FlagUtils.IsUnixFS(tempDir).Should().BeTrue();

                    FlagUtils.MarkAsNoUnixFS(tempDir);
                    FlagUtils.IsUnixFS(tempDir).Should().BeFalse();
                }
                else
                {
                    FlagUtils.IsUnixFS(tempDir).Should().BeFalse();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new store using a specific path to a cache directory.
        /// </summary>
        /// <param name="path">A fully qualified directory path. The directory will be created if it doesn't exist yet.</param>
        /// <param name="useWriteProtection">Controls whether implementation directories are made write-protected once added to the cache to prevent unintentional modification (which would invalidate the manifest digests).</param>
        /// <exception cref="IOException">The directory <paramref name="path"/> could not be created or if the underlying filesystem can not store file-changed times accurate to the second.</exception>
        /// <exception cref="UnauthorizedAccessException">Creating the directory <paramref name="path"/> is not permitted.</exception>
        public DirectoryStore([NotNull] string path, bool useWriteProtection = true)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            #endregion

            try
            {
                DirectoryPath = Path.GetFullPath(path);
                if (!Directory.Exists(DirectoryPath))
                {
                    Directory.CreateDirectory(DirectoryPath);
                }
            }
            #region Error handling
            catch (ArgumentException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(ex.Message, ex);
            }
            catch (NotSupportedException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(ex.Message, ex);
            }
            #endregion

            Kind = DetermineKind(DirectoryPath);
            _useWriteProtection = useWriteProtection;
            _isUnixFS           = FlagUtils.IsUnixFS(DirectoryPath);

            if (Kind == StoreKind.ReadWrite)
            {
                if (!_isUnixFS)
                {
                    FlagUtils.MarkAsNoUnixFS(DirectoryPath);
                }
                if (_useWriteProtection && WindowsUtils.IsWindowsNT)
                {
                    WriteDeleteInfoFile(DirectoryPath);
                }
            }
        }
Beispiel #4
0
        public void TestIsUnixFS()
        {
            using (var tempDir = new TemporaryDirectory("0install-unit-tests"))
            {
                if (UnixUtils.IsUnix)
                {
                    Assert.IsTrue(FlagUtils.IsUnixFS(tempDir));

                    FlagUtils.MarkAsNoUnixFS(tempDir);
                    Assert.IsFalse(FlagUtils.IsUnixFS(tempDir));
                }
                else
                {
                    Assert.IsFalse(FlagUtils.IsUnixFS(tempDir));
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Prepares to generate a manifest for a directory in the filesystem.
        /// </summary>
        /// <param name="path">The path of the directory to analyze.</param>
        /// <param name="format">The format of the manifest to generate.</param>
        public ManifestGenerator([NotNull] string path, [NotNull] ManifestFormat format)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            #endregion

            TargetDir = path.TrimEnd(Path.DirectorySeparatorChar);
            Format    = format;

            _isUnixFS = FlagUtils.IsUnixFS(TargetDir);
        }
 public CopyDirectoryPosix(string sourcePath, string destinationPath, bool preserveDirectoryTimestamps = true, bool overwrite = false)
     : base(sourcePath, destinationPath, preserveDirectoryTimestamps, overwrite)
 {
     _sourceIsUnixFS      = FlagUtils.IsUnixFS(SourcePath);
     _destinationIsUnixFS = FlagUtils.IsUnixFS(DestinationPath);
 }
Beispiel #7
0
        /// <summary>
        /// Creates a new store using a specific path to a cache directory.
        /// </summary>
        /// <param name="directoryPath">A fully qualified directory path. The directory will be created if it doesn't exist yet.</param>
        /// <param name="useWriteProtection">Controls whether implementation directories are made write-protected once added to the cache to prevent unintentional modification (which would invalidate the manifest digests).</param>
        /// <exception cref="IOException">The <paramref name="directoryPath"/> could not be created or the underlying filesystem can not store file-changed times accurate to the second.</exception>
        /// <exception cref="UnauthorizedAccessException">Creating the <paramref name="directoryPath"/> is not permitted.</exception>
        public DiskImplementationStore(string directoryPath, bool useWriteProtection = true)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(directoryPath))
            {
                throw new ArgumentNullException(nameof(directoryPath));
            }
            #endregion

            try
            {
                DirectoryPath = Path.GetFullPath(directoryPath);
                if (!Directory.Exists(DirectoryPath))
                {
                    Directory.CreateDirectory(DirectoryPath);
                }
            }
            #region Error handling
            catch (ArgumentException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(ex.Message, ex);
            }
            catch (NotSupportedException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(ex.Message, ex);
            }
            #endregion

            Kind = DetermineKind(DirectoryPath);
            _useWriteProtection = useWriteProtection;
            _isUnixFS           = FlagUtils.IsUnixFS(DirectoryPath);

            if (Kind == ImplementationStoreKind.ReadWrite)
            {
                try
                {
                    if (!_isUnixFS)
                    {
                        FlagUtils.MarkAsNoUnixFS(DirectoryPath);
                    }
                    if (_useWriteProtection && WindowsUtils.IsWindowsNT)
                    {
                        WriteDeleteInfoFile(DirectoryPath);
                    }
                }
                #region Error handling
                catch (IOException ex)
                {
                    // Writing these files is not critical
                    Log.Debug(ex);
                }
                catch (UnauthorizedAccessException ex)
                {
                    // Writing these files is not critical
                    Log.Debug(ex);
                }
                #endregion
            }
        }