Class: Index::Entry
- Inherits:
-
Struct
- Object
- Struct
- Index::Entry
- Defined in:
- lib/index/entry.rb
Class Method Summary collapse
- .create(pathname, oid, stat) ⇒ Object
- .create_from_db(pathname, item, n) ⇒ Object
- .mode_for_stat(stat) ⇒ Object
- .parse(data) ⇒ Object
Instance Method Summary collapse
- #basename ⇒ Object
- #key ⇒ Object
- #parent_directories ⇒ Object
- #stage ⇒ Object
- #stat_match?(stat) ⇒ Boolean
- #times_match?(stat) ⇒ Boolean
- #to_s ⇒ Object
- #update_stat(stat) ⇒ Object
Class Method Details
.create(pathname, oid, stat) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/index/entry.rb', line 20 def self.create(pathname, oid, stat) path = pathname.to_s mode = Entry.mode_for_stat(stat) flags = [path.bytesize, MAX_PATH_SIZE].min Entry.new( stat.ctime.to_i, stat.ctime.nsec, stat.mtime.to_i, stat.mtime.nsec, stat.dev, stat.ino, mode, stat.uid, stat.gid, stat.size, oid, flags, path) end |
.create_from_db(pathname, item, n) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/index/entry.rb', line 32 def self.create_from_db(pathname, item, n) path = pathname.to_s flags = (n << 12) | [path.bytesize, MAX_PATH_SIZE].min Entry.new(0, 0, 0, 0, 0, 0, item.mode, 0, 0, 0, item.oid, flags, path) end |
.mode_for_stat(stat) ⇒ Object
39 40 41 |
# File 'lib/index/entry.rb', line 39 def self.mode_for_stat(stat) stat.executable? ? EXECUTABLE_MODE : REGULAR_MODE end |
.parse(data) ⇒ Object
43 44 45 |
# File 'lib/index/entry.rb', line 43 def self.parse(data) Entry.new(*data.unpack(ENTRY_FORMAT)) end |
Instance Method Details
#basename ⇒ Object
59 60 61 |
# File 'lib/index/entry.rb', line 59 def basename Pathname.new(path).basename end |
#key ⇒ Object
47 48 49 |
# File 'lib/index/entry.rb', line 47 def key [path, stage] end |
#parent_directories ⇒ Object
55 56 57 |
# File 'lib/index/entry.rb', line 55 def parent_directories Pathname.new(path).descend.to_a[0..-2] end |
#stage ⇒ Object
51 52 53 |
# File 'lib/index/entry.rb', line 51 def stage (flags >> 12) & 0x3 end |
#stat_match?(stat) ⇒ Boolean
76 77 78 |
# File 'lib/index/entry.rb', line 76 def stat_match?(stat) mode == Entry.mode_for_stat(stat) and (size == 0 or size == stat.size) end |
#times_match?(stat) ⇒ Boolean
80 81 82 83 |
# File 'lib/index/entry.rb', line 80 def times_match?(stat) ctime == stat.ctime.to_i and ctime_nsec == stat.ctime.nsec and mtime == stat.mtime.to_i and mtime_nsec == stat.mtime.nsec end |
#to_s ⇒ Object
85 86 87 88 89 |
# File 'lib/index/entry.rb', line 85 def to_s string = to_a.pack(ENTRY_FORMAT) string.concat("\0") until string.bytesize % ENTRY_BLOCK == 0 string end |
#update_stat(stat) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/index/entry.rb', line 63 def update_stat(stat) self.ctime = stat.ctime.to_i self.ctime_nsec = stat.ctime.nsec self.mtime = stat.mtime.to_i self.mtime_nsec = stat.mtime.nsec self.dev = stat.dev self.ino = stat.ino self.mode = Entry.mode_for_stat(stat) self.uid = stat.uid self.gid = stat.gid self.size = stat.size end |