0

Long story short, I have a buggy Makefile that is missing a few prerequisite definitions and consequently accidentally relies on the "order" of files on disk (checked out from an SVN repo) as given by their inode number.*

This order seems to have changed after an SVN server migration (and, fair enough, this order is not something someone would deliberately rely upon). But the result is that my builds are broken, because the target that used to be built first (and triggered build of the prerequisite) is now built after other targets (that are erroneously missing that prerequisite).

I can fix the Makefile, but as a workaround for rebuilding older versions of the software (that still contain the Makefile bug), I would like a command or small script to:

  • recreate files and directories in ascending filename order
  • recursively across subdirectories
  • so the end result is inodes increase as filenames increase

Is this even possible?

Bash ideal but Python acceptable.

* I don't actually know that Make is visiting files in inode number, but it's definitely not doing it in alphabetical filename order. It could be modification time, but if so then the question is the same. If the order is completely random then the question is moot anyway. (I appreciate that it's likely to be specified as being arbitrary, but run with it).

  • 2
    Are you sure you need them in inode-increasing order, and not in the order they appear via readdir() which would be down to how they are stored in the directories. What file system is it? – Stéphane Chazelas May 2 '18 at 12:43
  • @StéphaneChazelas: Not sure at all, but the directory layout hasn't changed. This is XFS. – Lightness Races in Orbit May 2 '18 at 13:00
  • The recipe fulfillment order I'm seeing does match an ordering on inode (and not an ordering on (mtime,inode) pair or on filename). But that could be just a co-incidence, I don't know. The sample size is only six files so it's kind of hard to tell. – Lightness Races in Orbit May 2 '18 at 13:03
  • Does it match what you see in the ls -f output? – Stéphane Chazelas May 2 '18 at 13:08
  • @StéphaneChazelas: No, but I have to run ls -fR (the files are in multiple subdirs) and I believe that command's "grouping" of results into the subdirectories is masking the overall ordering. – Lightness Races in Orbit May 2 '18 at 13:38
0

Give this script a list of filenames in the order you want their mod times to be set. They'll be set in increasing order, 1 second apart.

#!/bin/sh
# touch++: run touch to set mod time of file arguments,
# starting at indicated time and increasing by 1 second
# for each argument
# mp, 5/2/2018
usage() {
    echo "Usage: $0 -d \"date\" FILE ..." >&2
}

while getopts "d:" opt
do
    case "$opt" in
        d)
            date="$OPTARG"
            ;;
        *)
            usage
            exit 1
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "$date" ]
then
    usage
    exit 1
fi
secs=$(date -d "$date" "+%s")
if [ $? != 0 ]
then
    usage
    exit 2
fi
echo setting times starting at $secs $(date -d "@$secs")
for f
do
    touch -m -t $(date -d "@$secs" "+%Y%m%d%H%M.%S") -- "$f"
    secs=$((secs + 1))
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.