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

Order files in cpio not kept #38

Open
phhusson opened this issue Oct 9, 2016 · 4 comments
Open

Order files in cpio not kept #38

phhusson opened this issue Oct 9, 2016 · 4 comments

Comments

@phhusson
Copy link
Owner

phhusson commented Oct 9, 2016

Because strip-cpio writes files to cpio-%d, when doing cat cpio-*, cpio-100 comes before cpio-25, which generates weird cases like the folder entry appearing AFTER the file entry.
The result being a cpio considered as corrupted

@nkk71
Copy link

nkk71 commented Oct 10, 2016

So it's just a "version sort" issue? If so, how about changing it from
cat cpio-* ramdisk2 > ramdisk.tmp
to:

rm -f ramdisk.tmp;
for f in ls -v cpio-*; do cat $f >> ramdisk.tmp; done;
cat ramdisk2 >> ramdisk.tmp;

markdown is preventing showing the backquote, so the command is:
for f in <backquote>ls -v cpio-*<backquote>; do cat $f >> ramdisk.tmp; done;

@bziemek
Copy link

bziemek commented Oct 10, 2016

Without changing strip-cpio or post-procrssing filenames: for f in cpio-{x-y}... or something with ls - 1v... or, printf...sort -V... with xargs.
The solution with for should be most compatible, but I'm on my mobile right now and can't really check into the options.

@nkk71
Copy link

nkk71 commented Oct 10, 2016

tested it, if it's done in script, you have to do this http://pastebin.com/PrMdhjdT

ls -v (although documented in the options) does not actually sort
sort does not have -V option

EDIT: oh and don't use f as a variable, as that's already being used and will cause a conflict in the repack command

@ghost
Copy link

ghost commented Dec 13, 2016

How about using filelist order from original cpio dump?

cd "${ramdisk_extract}"
gunzip -c "${bootimg_extract}"/ramdisk.gz | cpio -im
gunzip -c "${bootimg_extract}"/ramdisk.gz | cpio -it0 2>/dev/null > "${bootimg_extract}"/ramdisk.filelist0

doing manipluation, then

# remove deleted objects from ramdisk.filelist0
while read -r -d $'\0' filename ; do
    [[ -e "${filename}" || -L "${filename}" ]] && printf "%s\0" "${filename}" >> "${bootimg_extract}"/ramdisk.filelist0.new
done < "${bootimg_extract}"/ramdisk.filelist0

# add new objects to ramdisk.filelist0 and reset filestamp
find . ! -path . -printf "%P\0" | while IFS= read -r -d $'\0' filename ; do
    touch -h -t 197001010100 "${filename}"
    grep -qZ "^${filename}$" "${bootimg_extract}"/ramdisk.filelist0 || printf "%s\0" "${filename}" >> "${bootimg_extract}"/ramdisk.filelist0.new
done

# build new ramdisk (override extracted orig ramdisk.gz)
cpio --create --null --format='newc' --owner +0:+0 < "${bootimg_extract}"/ramdisk.filelist0.new | gzip -9 > "${bootimg_extract}"/ramdisk.gz
  • no build user leak into image (if non root script run)
  • cpio order will keep
  • no strip-cpio workaround
  • todo: assume 197001010100 timestamps
  • todo: symlink permission may change from original cpio

-lrw-r--r-- 1 0 0 13 Jan 1 1970 charger -> /sbin/healthd
+lrwxrwxrwx 1 0 0 13 Jan 1 1970 charger -> /sbin/healthd

  • todo: new cpio image include differ links counts (if root subdirs)

-drwxr-xr-x 1 0 0 0 Jan 1 1970 dev
+drwxr-xr-x 2 0 0 0 Jan 1 1970 dev

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

3 participants