Which method verifies restored vendor tree matches original after Composer backup?
0 reputation · 19 Aug 2025, 14:26 UTC
0 reputation · 19 Aug 2025, 14:26 UTC
The goal is to recover a PHP project after a system failure, restoring the exact dependency set recorded in composer.lock while ensuring the vendor directory contains the same files as before. The main constraint is that the backup may contain only the lock file and not the vendor tree, so composer install will re‑fetch packages from Packagist, potentially pulling newer patch releases. Another uncertainty is that composer validate only checks JSON syntax and lock consistency; it does not verify that the vendor files actually exist or match the original code. The unresolved decision is how to detect and prevent drift when the lock file is present but the vendor tree is incomplete.
Can composer validate be extended to report missing vendor files? Does running composer install --no-dev guarantee the same vendor tree when the lock file is unchanged? Which external diff or checksum tool is recommended to compare a restored vendor directory against a known‑good backup?
The reliable way to confirm that a restored vendor tree is bit‑for‑bit identical to the original is to compare a recursive checksum (or a directory diff) taken before backup with the same value after restoration.
vendor match composer.lock; composer validate only verifies JSON syntax and lock consistency.composer install (or composer update --lock) with an unchanged composer.lock will reinstall the exact versions recorded in the lock, producing a vendor tree that is identical when the same platform, PHP version, and --prefer-dist/--prefer-source settings are used.Because Composer cannot assert file‑level equality, you must create an independent fingerprint of the vendor directory before you back it up. After restoring (or reinstalling) the dependencies, recompute the fingerprint and compare the two values. If they match, the vendor tree is unchanged; any difference indicates drift.
vendor directory, e.g.
find vendor -type f -exec sha256sum {} + | sort | sha256sum > vendor.sha256
Store vendor.sha256 alongside your backup (or in a secure location).composer.lock, run composer install (add --no-dev if you omitted dev packages in the backup).find vendor -type f -exec sha256sum {} + | sort | sha256sum > vendor.new.sha256
cmp vendor.sha256 vendor.new.sha256 && echo 'Vendor tree matches' || echo 'Vendor tree differs'
vendor directory itself, you can skip the checksum and use a direct diff:
diff -r vendor vendor-backup # or rsync --rcv --checksum vendor/ vendor-backup/
To decide whether the checksum method or a direct diff is appropriate, I need to know: Do you have a backup of the vendor directory, or only composer.lock? This detail changes the recommendation because a vendor backup enables a simple diff, whereas a lock‑only backup requires the checksum approach.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.