Ejemplo n.º 1
0
        void ProcessObject(bool skipWhenLocalFileMatches, FileObjectMapping o,
                           ICollection <FileObjectMapping> validObjects)
        {
            if (skipWhenLocalFileMatches)
            {
                // We can also skip objects that already match in the working directory so that we don't waste time on compressing or copying objects needlessly
                // this however could create more bandwidth usage in case the user in the future deletes working files, and tries to get the version again
                // in that case the objects will need to be redownloaded, or at least patched up from other possible available objects.
                var path = WorkingPath.GetChildFileWithName(o.FilePath);
                if (path.Exists &&
                    Repository.GetChecksum(path).Equals(o.Checksum))
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the local object matches");
                    }
                    return;
                }

                var oPath = Repository.GetObjectPath(o.Checksum);
                if (oPath.Exists)
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the packed object exists");
                    }
                    // Don't readd object because we can't validate if the Checksum is in order..
                }
            }
            else
            {
                var ob = Repository.GetObject(o.Checksum);
                if (ob == null)
                {
                    return;
                }
                var oPath = Repository.GetObjectPath(o.Checksum);
                if (oPath.Exists && Repository.GetChecksum(oPath).Equals(ob.ChecksumPack))
                {
                    validObjects.Add(o);
                    if (Common.Flags.Verbose)
                    {
                        MainLog.Logger.Info(
                            $"Marking {o.FilePath} ({o.Checksum}) as valid, because the packed object matches");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void ProcessMissingObject(Package.ObjectMap o, ICollection <Package.ObjectMap> resolvedObjects)
        {
            var f = WorkingPath.GetChildFileWithName(o.FO.FilePath);

            if (!f.Exists)
            {
                return;
            }
            var status = new Status(o.FO.FilePath, StatusRepo)
            {
                Action     = RepoStatus.Packing,
                RealObject = GetObjectPathFromChecksum(o.FO)
            };
            var checksum = Repository.GetChecksum(f);

            this.Logger().Info("Found local previous version file for {0}. Compressing to {1}", o.FO.FilePath,
                               checksum);
            Repository.CompressObject(f, checksum);
            o.ExistingObject = checksum;
            resolvedObjects.Add(o);
            status.EndOutput();
        }