コード例 #1
0
ファイル: Extractor.cs プロジェクト: isabella232/0install-win
        /// <summary>
        /// Marks a file as executable using the filesystem if possible; stores it in a <see cref="FlagUtils.XbitFile"/> otherwise.
        /// </summary>
        /// <param name="relativePath">A path relative to the archive's root.</param>
        private void SetExecutableBit(string relativePath)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(relativePath))
            {
                throw new ArgumentNullException("relativePath");
            }
            #endregion

            if (_isUnixFS)
            {
                FileUtils.SetExecutable(Path.Combine(EffectiveTargetDir, relativePath), true);
            }
            else
            {
                // Non-Unixoid OSes (e.g. Windows) can't store the executable flag directly in the filesystem; remember in a text-file instead
                string flagRelativePath = string.IsNullOrEmpty(Destination) ? relativePath : Path.Combine(Destination, relativePath);
                FlagUtils.Set(Path.Combine(TargetDir, FlagUtils.XbitFile), flagRelativePath);
            }
        }
コード例 #2
0
        /// <summary>
        /// Deploys a reference file for a <see cref="Candidate"/> from an internal resource.
        /// </summary>
        /// <param name="reference">Uses <see cref="Candidate.RelativePath"/> as the resource name.</param>
        /// <param name="xbit">Set to <c>true</c> to mark the file as Unix executable.</param>
        /// <returns></returns>
        protected FileInfo Deploy(Candidate reference, bool xbit)
        {
            var file = new FileInfo(Path.Combine(Directory.FullName, reference.RelativePath));

            typeof(CandidateTest).CopyEmbeddedToFile(reference.RelativePath, file.FullName);

            if (xbit)
            {
                if (UnixUtils.IsUnix)
                {
                    FileUtils.SetExecutable(file.FullName, true);
                }
                else
                {
                    FlagUtils.Set(Path.Combine(Directory.FullName, FlagUtils.XbitFile), reference.RelativePath);
                }
            }

            return(file);
        }
コード例 #3
0
        /// <summary>
        /// Deploys a reference file for a <see cref="Candidate"/> from an internal resource.
        /// </summary>
        /// <param name="reference">Uses <see cref="Candidate.RelativePath"/> as the resource name.</param>
        /// <param name="xbit">Set to <see langword="true"/> to mark the file as Unix executable.</param>
        /// <returns></returns>
        protected FileInfo Deploy(Candidate reference, bool xbit)
        {
            var file = new FileInfo(Path.Combine(Directory.FullName, reference.RelativePath));

            using (var stream = typeof(CandidateTest).GetEmbeddedStream(reference.RelativePath))
                using (var fileStream = file.Create())
                    stream.CopyTo(fileStream);

            if (xbit)
            {
                if (UnixUtils.IsUnix)
                {
                    FileUtils.SetExecutable(file.FullName, true);
                }
                else
                {
                    FlagUtils.Set(Path.Combine(Directory.FullName, FlagUtils.XbitFile), reference.RelativePath);
                }
            }

            return(file);
        }
コード例 #4
0
        /// <summary>
        /// Creates a symbolic link in the filesystem if possible; stores it in a <see cref="FlagUtils.SymlinkFile"/> otherwise.
        /// </summary>
        /// <param name="source">A path relative to <see cref="SubDir"/>.</param>
        /// <param name="target">The target the symbolic link shall point to relative to <paramref name="source"/>. May use non-native path separators!</param>
        protected void CreateSymlink([NotNull] string source, [NotNull] string target)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentNullException(nameof(target));
            }
            #endregion

            string sourceAbsolute  = CombinePath(source);
            string sourceDirectory = Path.GetDirectoryName(sourceAbsolute);
            if (sourceDirectory != null && !Directory.Exists(sourceDirectory))
            {
                Directory.CreateDirectory(sourceDirectory);
            }

            if (_isUnixFS)
            {
                FileUtils.CreateSymlink(sourceAbsolute, target);
            }
            else if (WindowsUtils.IsWindowsNT)
            {
                // NOTE: NTFS symbolic links require admin privileges; use Cygwin symlinks instead
                CygwinUtils.CreateSymlink(sourceAbsolute, target);
            }
            else
            {
                // Write link data as a normal file
                File.WriteAllText(sourceAbsolute, target);

                // Some OSes can't store the symlink flag directly in the filesystem; remember in a text-file instead
                string flagRelativePath = string.IsNullOrEmpty(Destination) ? source : Path.Combine(Destination, source);
                FlagUtils.Set(Path.Combine(TargetDir, FlagUtils.SymlinkFile), flagRelativePath);
            }
        }