Skip to content

Commit

Permalink
add more properties for entry type
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
Changaco committed Apr 28, 2015
1 parent 947aec0 commit 4438568
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
26 changes: 25 additions & 1 deletion libarchive/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,33 @@ def get_blocks(self, block_size=ffi.page_size):
break
yield buf.raw[0:r]

@property
def isblk(self):
return self.filetype & 0o170000 == 0o060000

@property
def ischr(self):
return self.filetype & 0o170000 == 0o020000

@property
def isdir(self):
return bool(self.filetype & ffi.AE_IFDIR)
return self.filetype & 0o170000 == 0o040000

@property
def isfifo(self):
return self.filetype & 0o170000 == 0o010000

@property
def islnk(self):
return self.filetype & 0o170000 == 0o120000

@property
def isreg(self):
return self.filetype & 0o170000 == 0o100000

@property
def issock(self):
return self.filetype & 0o170000 == 0o140000

@property
def mtime(self):
Expand Down
9 changes: 0 additions & 9 deletions libarchive/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@
ARCHIVE_FAILED = -25 # Current operation cannot complete.
ARCHIVE_FATAL = -30 # No more operations are possible.

AE_IFMT = 0o170000
AE_IFREG = 0o100000
AE_IFLNK = 0o120000
AE_IFSOCK = 0o140000
AE_IFCHR = 0o020000
AE_IFBLK = 0o060000
AE_IFDIR = 0o040000
AE_IFIFO = 0o010000


# Callback types

Expand Down
7 changes: 7 additions & 0 deletions tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ def test_entry_properties():
with memory_reader(buf) as archive:
for entry in archive:
assert entry.mode == stat('README.rst')[0]
assert not entry.isblk
assert not entry.ischr
assert not entry.isdir
assert not entry.isfifo
assert not entry.islnk
assert entry.isreg
assert not entry.issock
assert b'rw' in entry.strmode

0 comments on commit 4438568

Please sign in to comment.