Exemplo n.º 1
0
        /// <summary>
        /// Save the data in lock file.
        /// </summary>
        public bool Save()
        {
            // Even empty objects should be written.
            var locker = new ConfigLocker
            {
                Packages       = LockPackages(packages),
                PackagesDev    = LockPackages(packagesDev),
                Aliases        = aliases ?? Array.Empty <ConfigAlias>(),
                StabilityFlags = NormalizeStabilityFlags(stabilityFlags),
                Platforms      = platforms ?? new Dictionary <string, string>(),
            };

            if (minimumStability != null)
            {
                locker.MinimumStability = minimumStability.Value;
            }

            if (preferStable != null)
            {
                locker.PreferStable = preferStable.Value;
            }

            if (preferLowest != null)
            {
                locker.PreferLowest = preferLowest.Value;
            }

            return(doSetLockData(locker));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Locks provided data into lockfile.
        /// </summary>
        /// <param name="locker">The lock data.</param>
        private bool SetLockData(ConfigLocker locker)
        {
            locker.ContentHash = contentHash;

            if (locker.Packages.Empty() && locker.PackagesDev.Empty())
            {
                lockFile.Delete();
                return(false);
            }

            bool isLocked;

            try
            {
                isLocked = IsLocked();
            }
            catch (RuntimeException)
            {
                isLocked = false;
            }

            if (!isLocked || !LockerAreEqual(locker, GetLockerData()))
            {
                cache = null;
                lockFile.Write(locker);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the bucket.lock configuration.
        /// </summary>
        public virtual ConfigLocker GetLockerData()
        {
            if (cache != null)
            {
                return(cache);
            }

            if (!lockFile.Exists())
            {
                throw new RuntimeException("No lockfile found. Unable to read locked packages.");
            }

            return(cache = lockFile.Read <ConfigLocker>());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Whether the locker are equal.
 /// </summary>
 internal static bool LockerAreEqual(ConfigLocker x, ConfigLocker y)
 {
     // todo: need optimization.
     return(Security.Md5(JsonConvert.SerializeObject(x)) == Security.Md5(JsonConvert.SerializeObject(y)));
 }