GitSharp.Core.DirectoryCache.DirCacheEntry.mightBeRacilyClean C# (CSharp) Method

mightBeRacilyClean() public method

Is it possible for this entry to be accidentally assumed clean? The "racy git" problem happens when a work file can be updated faster than the filesystem records file modification timestamps. It is possible for an application to edit a work file, update the index, then edit it again before the filesystem will give the work file a new modification timestamp. This method tests to see if file was written out at the same time as the index.
public mightBeRacilyClean ( int smudge_s, int smudge_ns ) : bool
smudge_s int /// Seconds component of the index's last modified time. ///
smudge_ns int /// Nanoseconds component of the index's last modified time. ///
return bool
        public bool mightBeRacilyClean(int smudge_s, int smudge_ns)
        {
            // If the index has a modification time then it came from disk
            // and was not generated from scratch in memory. In such cases
            // the entry is 'racily clean' if the entry's cached modification
            // time is equal to or later than the index modification time. In
            // such cases the work file is too close to the index to tell if
            // it is clean or not based on the modification time alone.
            //
            int @base = _infoOffset + PMtime;
            int mtime = NB.DecodeInt32(_info, @base);
            if (smudge_s < mtime) return true;

            if (smudge_s == mtime)
                return smudge_ns <= NB.DecodeInt32(_info, @base + 4) / 1000000;

            return false;
        }

Usage Example

Ejemplo n.º 1
0
        private void WriteTo(Stream os)
        {
            MessageDigest foot = Constants.newMessageDigest();
            var           dos  = new DigestOutputStream(os, foot);

            // Write the header.
            //
            var tmp = new byte[128];

            Array.Copy(SigDirc, 0, tmp, 0, SigDirc.Length);
            NB.encodeInt32(tmp, 4, /* version */ 2);
            NB.encodeInt32(tmp, 8, _entryCnt);
            dos.Write(tmp, 0, 12);

            // Write the individual file entries.
            //
            if (_lastModified <= 0)
            {
                // Write a new index, as no entries require smudging.
                //
                for (int i = 0; i < _entryCnt; i++)
                {
                    _sortedEntries[i].write(dos);
                }
            }
            else
            {
                int smudge_s  = (int)(_lastModified / 1000);
                int smudge_ns = ((int)(_lastModified % 1000)) * 1000000;
                for (int i = 0; i < _entryCnt; i++)
                {
                    DirCacheEntry e = _sortedEntries[i];
                    if (e.mightBeRacilyClean(smudge_s, smudge_ns))
                    {
                        e.smudgeRacilyClean();
                    }
                    e.write(dos);
                }
            }

            if (_cacheTree != null)
            {
                var bb = new LocalFileBuffer();
                _cacheTree.write(tmp, bb);
                bb.close();

                NB.encodeInt32(tmp, 0, ExtTree);
                NB.encodeInt32(tmp, 4, (int)bb.Length);
                dos.Write(tmp, 0, 8);
                bb.writeTo(dos, null);
            }
            var hash = foot.Digest();

            os.Write(hash, 0, hash.Length);
            os.Close();
        }
All Usage Examples Of GitSharp.Core.DirectoryCache.DirCacheEntry::mightBeRacilyClean