Welcome to the Linux Foundation Forum!

Order of files in Lab 13.1

donaldsebleungdonaldsebleung Posts: 2
edited August 1 in LFW211 Class Forum

I noticed that Labs 1 and 2 for Chapter 13 are swapped in the downloadable course resources relative to the online course notes, so let me first be clear that I am referring to "Lab 13.1 - Read Directory and Write File" from the online course notes.

For this lab, I have been able to list the files under the project directory and write them to out.txt; however, it often does so in a different order than the expected order (in particular, my list is sorted in alphanumeric order) so I get an assertion failure, e.g.

  ...
  actual: [
    '1lro5348nq3',
    'ab5hmkwhvap',
    'mgofil6hjz9',
    'tm4q0z9dp1d',
    'x637x6xphlc'
  ],
  expected: [
    'tm4q0z9dp1d',
    'ab5hmkwhvap',
    'x637x6xphlc',
    'mgofil6hjz9',
    '1lro5348nq3'
  ],
  ...

Should I consider myself to have passed the lab in this case, or should the order of the listed files match that of the expected output? In the latter case, I also tried sorting the files in ascending order based on creation time (by stat.birthtimeMs) but to no avail - perhaps the creation times of the files are too close together to be distinguished in the millisecond range?

Comments

  • I just managed to produce the exact output expected by the assertions (consistently). From the Node.js documentation on fs.Stats, the stats object contains the inode number of the file through the ino property, and I figured by inspecting the inode numbers of the generated files (ls -i on POSIX systems) that the test cases expect the files to be listed in ascending inode number (= ascending order of creation time?), so I sorted my file list by inode number before writing them to out.txt and passed the assertions that way.

Sign In or Register to comment.