Skip to content
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

mtime is incorrectly read as 0 #349

Open
konstin opened this issue Dec 13, 2023 · 0 comments
Open

mtime is incorrectly read as 0 #349

konstin opened this issue Dec 13, 2023 · 0 comments

Comments

@konstin
Copy link

konstin commented Dec 13, 2023

For certain tar file, the tar command on ubuntu 23.10 and tarfile in the python 3.11 standard library read the correct mtime, while tar-rs claims it's 0. Example: https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz

tar-rs prints 0:

use flate2::read::GzDecoder;
use std::fs::File;
use std::path::Path;
use tar::Archive;

fn main() {
    let mut archive = Archive::new(GzDecoder::new(File::open("tomli-2.0.1.tar.gz").unwrap()));
    let entry = archive
        .entries()
        .unwrap()
        .map(|entry| entry.unwrap())
        .find(|entry| {
            entry.path().unwrap().as_ref() == Path::new("tomli-2.0.1/src/tomli/__init__.py")
        })
        .unwrap();
    println!("{}", entry.header().mtime().unwrap());
}

python prints 1644317623.2803335:

import tarfile

if __name__ == '__main__':
    archive = tarfile.open("tomli-2.0.1.tar.gz")
    init_py = archive.getmember("tomli-2.0.1/src/tomli/__init__.py")
    print(init_py.mtime)

tar sets the same timestamp:

$ tar xf tomli-2.0.1.tar.gz
$ ls -al --full-time tomli-2.0.1/src/tomli/__init__.py
-rw-r--r-- 1 konsti konsti 396 2022-02-08 11:53:43.280333500 +0100 tomli-2.0.1/src/tomli/__init__.py

This creates a problem because the timstamps are by default inferred to unix time 1 (~1970), while python std's zipfile library does not support timestamps before 1980.

konstin added a commit to astral-sh/uv that referenced this issue Dec 13, 2023
charliermarsh pushed a commit to astral-sh/uv that referenced this issue Dec 13, 2023
konstin added a commit to astral-sh/uv that referenced this issue Dec 13, 2023
tdejager pushed a commit to prefix-dev/rip that referenced this issue Feb 15, 2024
These PR address 2 major issues and 1 small issue
* zip file stamps issue
alexcrichton/tar-rs#349 which we encountered
when installing tomli-2.1.0
* changed from_filename signature so it can also produce Stree, which
it's needed from pixi side
* lowercase Root-Is-Purelib so we can install elsie library (
prefix-dev/pixi#771 (comment))
konstin added a commit to astral-sh/uv that referenced this issue Feb 20, 2024
Don't preserve mtime to work around alexcrichton/tar-rs#349. Same as #634 except for the streaming unzip.

Fixes #1748.
charliermarsh pushed a commit to astral-sh/uv that referenced this issue Feb 20, 2024
## Summary

Don't preserve mtime to work around alexcrichton/tar-rs#349. Same as
#634 except for the streaming unzip.

Fixes #1748.

## Test Plan

Added the tomli source dist as test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant