-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setters for ctime, mtime and atime. #50
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from __future__ import division, print_function, unicode_literals | ||
|
||
from ctypes import ( | ||
c_char_p, c_int, c_uint, c_longlong, c_size_t, c_void_p, | ||
c_char_p, c_int, c_uint, c_long, c_longlong, c_size_t, c_void_p, | ||
c_wchar_p, CFUNCTYPE, POINTER, | ||
) | ||
|
||
|
@@ -127,9 +127,12 @@ def ffi(name, argtypes, restype, errcheck=None): | |
ffi('entry_rdevmajor', [c_archive_entry_p], c_uint) | ||
ffi('entry_rdevminor', [c_archive_entry_p], c_uint) | ||
|
||
ffi('entry_set_size', [c_archive_entry_p, c_longlong], c_int) | ||
ffi('entry_set_size', [c_archive_entry_p, c_longlong], c_longlong) | ||
ffi('entry_set_filetype', [c_archive_entry_p, c_int], c_int) | ||
ffi('entry_set_perm', [c_archive_entry_p, c_int], c_int) | ||
ffi('entry_set_atime', [c_archive_entry_p, c_int, c_long], None) | ||
ffi('entry_set_mtime', [c_archive_entry_p, c_int, c_long], None) | ||
ffi('entry_set_ctime', [c_archive_entry_p, c_int, c_long], None) | ||
|
||
ffi('entry_update_pathname_utf8', [c_archive_entry_p, c_char_p], None) | ||
|
||
|
@@ -240,5 +243,7 @@ def ffi(name, argtypes, restype, errcheck=None): | |
c_int, check_int) | ||
ffi('write_finish_entry', [c_archive_p], c_int, check_int) | ||
|
||
ffi('write_fail', [c_archive_p], c_int, check_int) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't seem to be used, why do you want to add it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not used directly by any of context managers in python-libarchive-c, but we use it in our project to allow cancelling creation of archive. Since this library is a convenient wrapper around libarchive we think that it's the best place for it (and make this wrapper more complete). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then shouldn't the context managers call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created a separate issue for that: #51. |
||
ffi('write_close', [c_archive_p], c_int, check_int) | ||
ffi('write_free', [c_archive_p], c_int, check_int) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from __future__ import division, print_function, unicode_literals | ||
|
||
from copy import copy | ||
from os import stat | ||
|
||
from libarchive import (file_reader, file_writer, memory_reader, | ||
memory_writer) | ||
|
||
from . import treestat | ||
|
||
|
||
def check_atime_ctime(archive, tree): | ||
tree2 = copy(tree) | ||
for entry in archive: | ||
epath = str(entry).rstrip('/') | ||
assert epath in tree2 | ||
estat = tree2.pop(epath) | ||
assert entry.atime == int(estat['atime']) | ||
assert entry.ctime == int(estat['ctime']) | ||
|
||
|
||
def stat_dict(path): | ||
_, _, _, _, _, _, _, atime, _, ctime = stat(path) | ||
return {"atime": atime, "ctime": ctime} | ||
|
||
|
||
def test_memory_atime_ctime(): | ||
# Collect information on what should be in the archive | ||
tree = treestat('libarchive', stat_dict) | ||
|
||
# Create an archive of our libarchive/ directory | ||
buf = bytes(bytearray(1000000)) | ||
with memory_writer(buf, 'zip') as archive1: | ||
archive1.add_files('libarchive/') | ||
|
||
# Check the data | ||
with memory_reader(buf) as archive2: | ||
check_atime_ctime(archive2, tree) | ||
|
||
|
||
def test_file_atime_ctime(tmpdir): | ||
archive_path = tmpdir.strpath+'/test.zip' | ||
|
||
# Collect information on what should be in the archive | ||
tree = treestat('libarchive', stat_dict) | ||
|
||
# Create an archive of our libarchive/ directory | ||
with file_writer(archive_path, 'zip') as archive: | ||
archive.add_files('libarchive/') | ||
|
||
# Read the archive and check that the data is correct | ||
with file_reader(archive_path) as archive: | ||
check_atime_ctime(archive, tree) | ||
|
||
|
||
def test_memory_time_setters(): | ||
# Create an archive of our libarchive/ directory | ||
|
||
atimestamp = (1482144741, 495628118) | ||
mtimestamp = (1482155417, 659017086) | ||
ctimestamp = (1482145211, 536858081) | ||
buf = bytes(bytearray(1000000)) | ||
with memory_writer(buf, "zip") as archive1: | ||
archive1.add_files('libarchive/') | ||
|
||
buf2 = bytes(bytearray(1000000)) | ||
with memory_reader(buf) as archive1: | ||
with memory_writer(buf2, "zip") as archive2: | ||
for entry in archive1: | ||
entry.set_atime(*atimestamp) | ||
entry.set_mtime(*mtimestamp) | ||
entry.set_ctime(*ctimestamp) | ||
archive2.add_entries([entry]) | ||
|
||
with memory_reader(buf2) as archive2: | ||
for entry in archive2: | ||
assert entry.atime == atimestamp[0] | ||
assert entry.mtime == mtimestamp[0] | ||
assert entry.ctime == ctimestamp[0] | ||
|
||
|
||
def test_file_time_setters(tmpdir): | ||
# Create an archive of our libarchive/ directory | ||
archive_path = tmpdir.join('/test.zip').strpath | ||
archive2_path = tmpdir.join('/test2.zip').strpath | ||
|
||
atimestamp = (1482144741, 495628118) | ||
mtimestamp = (1482155417, 659017086) | ||
ctimestamp = (1482145211, 536858081) | ||
with file_writer(archive_path, "zip") as archive1: | ||
archive1.add_files('libarchive/') | ||
|
||
with file_reader(archive_path) as archive1: | ||
with file_writer(archive2_path, "zip") as archive2: | ||
for entry in archive1: | ||
entry.set_atime(*atimestamp) | ||
entry.set_mtime(*mtimestamp) | ||
entry.set_ctime(*ctimestamp) | ||
archive2.add_entries([entry]) | ||
|
||
with file_reader(archive2_path) as archive2: | ||
for entry in archive2: | ||
assert entry.atime == atimestamp[0] | ||
assert entry.mtime == mtimestamp[0] | ||
assert entry.ctime == ctimestamp[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this change is necessary to allow compressing big files (our files are huge).
BTW longlong is the type that actually matches the C signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't match the signature. The
archive_entry_set_*
functions don't actually return anything (void
), so the last argument toffi
should probably beNone
. I'm not sure why it's currentlyc_int
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought about this commit f301a92
yes, it's completely unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Changaco should I change it back to
c_int
or toNone
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed them to
None
. The tests passed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I was at it I changed the argument type of
entry_set_filetype
fromc_int
toc_uint
since the C signature saysunsigned int
.