示例#1
0
        /// <summary>
        /// Transfer the permissions of the source file(or dir) to the target file(or dir).
        /// </summary>
        /// <remarks>It is not allowed to pass permissions between folders and files, this will return false.</remarks>
        /// <returns>True if transfer successful. false if the <paramref name="destination"/> not exists.</returns>
        public static bool TransferPerms(string source, string destination)
        {
            if (!FileSystem.Exists(source) || !FileSystem.Exists(destination))
            {
                return(false);
            }

            var sourceIsDir      = FileSystemLocal.IsDirectory(source);
            var destinationIsDir = FileSystemLocal.IsDirectory(destination);

            // Ensure source is same type for the destination.
            if (sourceIsDir != destinationIsDir)
            {
                return(false);
            }

            if (Platform.IsWindows)
            {
                return(PermissionWindows.TransferPerms(source, destination, sourceIsDir));
            }

            return(PermissionUnix.TransferPerms(source, destination));
        }
示例#2
0
        public void TestExists()
        {
            WriteAllText("foo", "foo");
            WriteAllText("bar/bar", "bar");

            Assert.AreEqual(true, fileSystem.Exists("foo"));
            Assert.AreEqual(true, fileSystem.Exists("bar/bar"));
            Assert.AreEqual(true, fileSystem.Exists("bar"));

            Assert.AreEqual(false, fileSystem.Exists("baz"));
            Assert.AreEqual(false, fileSystem.Exists("bar/baz"));

            Assert.AreEqual(false, fileSystem.Exists("bar", FileSystemOptions.File));
            Assert.AreEqual(true, fileSystem.Exists("bar", FileSystemOptions.Directory));

            Assert.AreEqual(true, fileSystem.Exists("foo", FileSystemOptions.File));
            Assert.AreEqual(false, fileSystem.Exists("foo", FileSystemOptions.Directory));
        }
示例#3
0
        /// <inheritdoc />
        protected override int Execute(IInput input, IOutput output)
        {
            var file       = input.GetArgument("file") ?? Factory.GetBucketFile();
            var io         = GetIO();
            var fileSystem = new FileSystemLocal();

            if (!fileSystem.Exists(file))
            {
                io.WriteError($"<error>{file} not found.</error>");
                return(ExitCodes.FileNotFoundException);
            }

            var checkPublish = !input.GetOption("no-check-publish");
            var checkLock    = !input.GetOption("no-check-lock");
            var isStrict     = input.GetOption("strict");

            var validator = new ValidatorBucket(fileSystem, io);

            var(warnings, publishErrors, errors) = validator.Validate(file);

            var lockErrors = Array.Empty <string>();
            var bucket     = Factory.Create(io, file, input.HasRawOption("--no-plugins"));
            var locker     = bucket.GetLocker();

            if (locker.IsLocked() && !locker.IsFresh())
            {
                lockErrors = new[] { "The lock file is not up to date with the latest changes in bucket.json, it is recommended that you run `bucket update`." };
            }

            OuputResult(file, ref errors, ref warnings, checkPublish, publishErrors, checkLock, lockErrors, isStrict);

            int GetStrictExitCode()
            {
                return((isStrict && !warnings.Empty()) ? ExitCodes.ValidationWarning : GameBox.Console.ExitCodes.Normal);
            }

            var exitCode = errors.Length > 0 ? ExitCodes.ValidationErrors : GetStrictExitCode();

            if (input.GetOption("with-dependencies"))
            {
                var localInstalledRepository = bucket.GetRepositoryManager().GetLocalInstalledRepository();
                foreach (var package in localInstalledRepository.GetPackages())
                {
                    var path = bucket.GetInstallationManager().GetInstalledPath(package);
                    file = Path.Combine(path, "bucket.json");

                    if (!Directory.Exists(path) || !File.Exists(file))
                    {
                        continue;
                    }

                    (warnings, publishErrors, errors) = validator.Validate(file);
                    OuputResult(file, ref errors, ref warnings, checkPublish, publishErrors, isStrict: isStrict);

                    var depCode = !errors.Empty() ? ExitCodes.ValidationErrors : GetStrictExitCode();
                    exitCode = Math.Max(depCode, exitCode);
                }
            }

            var commandEvent = new CommandEventArgs(PluginEvents.Command, "validate", input, output);

            bucket.GetEventDispatcher().Dispatch(this, commandEvent);

            return(Math.Max(exitCode, commandEvent.ExitCode));
        }