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

preserve the original file order for sequential access #87

Open
milahu opened this issue Jul 25, 2024 · 0 comments
Open

preserve the original file order for sequential access #87

milahu opened this issue Jul 25, 2024 · 0 comments

Comments

@milahu
Copy link

milahu commented Jul 25, 2024

i want to download large torrents with many files in sequential order
and process the content files in their original order in the torrent
which is some random sort order, not abc order

currently ls -U returns files in abc order, not in the original order

man ls

       -U     do not sort; list entries in directory order

when i have access to the torrent file, i can do

mkdir mount_dir
btfs test.torrent mount_dir

torrenttools show files test.torrent | while read path; do
  md5sum mount_dir/*/"$path"
done

fusermount -u mount_dir

... but ideally this should also work via the filesystem

to make this work recursively
we could abuse the file times to encode the file order

all file times (atime, btime, ctime, mtime) should be set to some pseudo time
for example timestamp zero (year 1970) plus the file index as seconds

so i get sequential access with

mkdir mount_dir
btfs test.torrent mount_dir

# %T = mtime
find mount_dir/ -type f -printf '%T@ %P\n' | sort -n | cut -c23- | while read path; do
  md5sum "$path"
done

fusermount -u mount_dir

based on How to recursively find and list the latest modified files in a directory with subdirectories and times

current file times:
mtime = mount time
atime = zero
ctime = zero
btime = missing

$ TZ=C stat mount_dir/aaa/bbb
  File: mount_dir/aaa/bbb
  Size: 481515          Blocks: 0          IO Block: 4096   regular file
Device: 0,76    Inode: 24029       Links: 0
Access: (0444/-r--r--r--)  Uid: ( 1000/    user)   Gid: (  100/   users)
Access: 1970-01-01 00:00:00.000000000 +0000
Modify: 2024-07-25 20:36:48.000000000 +0000
Change: 1970-01-01 00:00:00.000000000 +0000
 Birth: -
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