You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

192 lines
5.7 KiB

  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test the 'guix-register' command-line utility.
  20. #
  21. guix-register --version
  22. new_store="t-register-$$"
  23. closure="t-register-closure-$$"
  24. rm -rf "$new_store"
  25. exit_hook=":"
  26. trap "chmod -R +w $new_store ; rm -rf $new_store $closure ; \$exit_hook" EXIT
  27. #
  28. # Registering items in the current store---i.e., without '--prefix'.
  29. #
  30. new_file="$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-guix-register-$$"
  31. echo "Fake store file to test registration." > "$new_file"
  32. # Register the file with zero references and no deriver.
  33. guix-register <<EOF
  34. $new_file
  35. 0
  36. EOF
  37. # Register an idendical file, and make sure it gets deduplicated.
  38. new_file2="$new_file-duplicate"
  39. cat "$new_file" > "$new_file2"
  40. guix-register <<EOF
  41. $new_file2
  42. 0
  43. EOF
  44. guile -c "
  45. (exit (= (stat:ino (stat \"$new_file\"))
  46. (stat:ino (stat \"$new_file2\"))))"
  47. # Make sure both are valid.
  48. guile -c "
  49. (use-modules (guix store))
  50. (define s (open-connection))
  51. (exit (and (valid-path? s \"$new_file\")
  52. (valid-path? s \"$new_file2\")
  53. (null? (references s \"$new_file\"))
  54. (null? (references s \"$new_file2\"))))"
  55. #
  56. # Registering items in a new store, with '--prefix'.
  57. #
  58. mkdir -p "$new_store/$storedir"
  59. new_store_dir="`cd "$new_store/$storedir" ; pwd -P`"
  60. new_store="`cd "$new_store" ; pwd -P`"
  61. to_copy="`guix build guile-bootstrap`"
  62. cp -r "$to_copy" "$new_store_dir"
  63. copied="$new_store_dir/`basename $to_copy`"
  64. # Create a file representing a closure with zero references, and with an empty
  65. # "deriver" field. Note that we give the file name as it appears in the
  66. # original store, and 'guix-register' translates it to match the prefix.
  67. cat >> "$closure" <<EOF
  68. $to_copy
  69. 0
  70. EOF
  71. # Register it.
  72. guix-register -p "$new_store" < "$closure"
  73. # Doing it a second time shouldn't hurt.
  74. guix-register --prefix "$new_store" "$closure"
  75. # Same, but with the database stored in a different place.
  76. guix-register -p "$new_store" \
  77. --state-directory "$new_store/chbouib" "$closure"
  78. # Register duplicate files.
  79. cp "$new_file" "$new_file2" "$new_store_dir"
  80. guix-register -p "$new_store" <<EOF
  81. $new_file
  82. 0
  83. EOF
  84. guix-register -p "$new_store" <<EOF
  85. $new_file2
  86. 0
  87. EOF
  88. copied_duplicate1="$new_store_dir/`basename $new_file`"
  89. copied_duplicate2="$new_store_dir/`basename $new_file2`"
  90. # Make sure there is indeed deduplication under $new_store and that there are
  91. # no cross-store hard links.
  92. guile -c "
  93. (exit (and (= (stat:ino (stat \"$copied_duplicate1\"))
  94. (stat:ino (stat \"$copied_duplicate2\")))
  95. (not (= (stat:ino (stat \"$new_file\"))
  96. (stat:ino (stat \"$copied_duplicate1\"))))))"
  97. # Delete them.
  98. guix gc -d "$new_file" "$new_file2"
  99. # Now make sure this is recognized as valid.
  100. ls -R "$new_store"
  101. for state_dir in "$localstatedir/guix" "/chbouib"
  102. do
  103. NIX_STORE_DIR="$new_store_dir"
  104. NIX_STATE_DIR="$new_store$state_dir"
  105. NIX_LOG_DIR="$new_store$state_dir/log/guix"
  106. NIX_DB_DIR="$new_store$state_dir/db"
  107. GUIX_DAEMON_SOCKET="$NIX_STATE_DIR/daemon-socket/socket"
  108. export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \
  109. NIX_LOG_DIR NIX_DB_DIR GUIX_DAEMON_SOCKET
  110. # Check whether we overflow the limitation on local socket name lengths.
  111. if [ `echo "$GUIX_DAEMON_SOCKET" | wc -c` -ge 108 ]
  112. then
  113. # Mark the test as skipped even though we already did some work so
  114. # that the remainder is not silently skipped.
  115. exit 77
  116. fi
  117. guix-daemon --disable-chroot &
  118. subdaemon_pid=$!
  119. exit_hook="kill $subdaemon_pid"
  120. final_name="$storedir/`basename $to_copy`"
  121. # At this point the copy in $new_store must be valid, and unreferenced.
  122. # The database under $NIX_DB_DIR uses the $final_name, but we can't use
  123. # that name in a 'valid-path?' query because 'assertStorePath' would kill
  124. # us because of the wrong prefix. So we just list dead paths instead.
  125. guile -c "
  126. (use-modules (guix store) (srfi srfi-1) (srfi srfi-34))
  127. (define s
  128. (let loop ((i 5))
  129. (guard (c ((nix-connection-error? c)
  130. (if (<= i 0)
  131. (raise c)
  132. (begin
  133. (display \"waiting for daemon socket...\")
  134. (newline)
  135. (sleep 1)
  136. (loop (- i 1))))))
  137. (open-connection \"$GUIX_DAEMON_SOCKET\"))))
  138. (exit (lset= string=?
  139. (pk 1 (list \"$copied\" \"$copied_duplicate1\"
  140. \"$copied_duplicate2\"))
  141. (pk 2 (dead-paths s))))"
  142. # Kill the daemon so we can access the database below (otherwise we may
  143. # get "database is locked" errors.)
  144. kill $subdaemon_pid
  145. exit_hook=":"
  146. while kill -0 $subdaemon_pid ; do sleep 0.5 ; done
  147. # When 'sqlite3' is available, check the name in the database.
  148. if type -P sqlite3
  149. then
  150. echo "select * from ValidPaths where path=\"$final_name\";" | \
  151. sqlite3 "$NIX_DB_DIR/db.sqlite"
  152. fi
  153. done