@@ -25,22 +25,36 @@ proc updateSha1Checksum(checksum: var Sha1State, fileName, filePath: string) =
2525 # directory from which no files are being installed.
2626 return
2727 checksum.update (fileName)
28- var file: File
29- try :
30- file = filePath.open (fmRead)
31- except IOError :
32- # # If the file cannot be open for reading do not count its content in the
33- # # checksum.
34- displayWarning (& " The file \" { filePath} \" cannot be open for reading.\n " &
35- " Skipping it in the calculation of the checksum." )
36- return
37- defer : close (file)
38- const bufferSize = 8192
39- var buffer = newString (bufferSize)
40- while true :
41- var bytesRead = readChars (file, buffer)
42- if bytesRead == 0 : break
43- checksum.update (buffer.toOpenArray (0 , bytesRead - 1 ))
28+ if symlinkExists (filePath):
29+ # Check whether a file is a symbolic link and if so update the checksum with
30+ # the path to the file that the link points to.
31+ var linkPath: string
32+ try :
33+ linkPath = expandSymlink (filePath)
34+ except OSError :
35+ displayWarning (& " Cannot expand symbolic link \" { filePath} \" .\n " &
36+ " Skipping it in the calculation of the checksum." )
37+ return
38+ checksum.update (linkPath)
39+ else :
40+ # Otherwise this is an ordinary file and we are adding its content to the
41+ # checksum.
42+ var file: File
43+ try :
44+ file = filePath.open (fmRead)
45+ except IOError :
46+ # # If the file cannot be open for reading do not count its content in the
47+ # # checksum.
48+ displayWarning (& " The file \" { filePath} \" cannot be open for reading.\n " &
49+ " Skipping it in the calculation of the checksum." )
50+ return
51+ defer : close (file)
52+ const bufferSize = 8192
53+ var buffer = newString (bufferSize)
54+ while true :
55+ var bytesRead = readChars (file, buffer)
56+ if bytesRead == 0 : break
57+ checksum.update (buffer.toOpenArray (0 , bytesRead - 1 ))
4458
4559proc calculateDirSha1Checksum * (dir: string ): Sha1Hash =
4660 # # Recursively calculates the sha1 checksum of the contents of the directory
0 commit comments