Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashfile() yields a different output depending on the OS #397

Closed
ThierryO opened this issue Aug 14, 2019 · 1 comment
Closed

hashfile() yields a different output depending on the OS #397

ThierryO opened this issue Aug 14, 2019 · 1 comment

Comments

@ThierryO
Copy link
Member

Below is a reprex. This causes a bug in the git2rdata package when switching between OS (ropensci/git2rdata#49).

library(git2r)
filename <- tempfile("os-bug")
writeLines(
  c("x\ty", "1\t1", "2\t2", "3\t3", "4\t4", "5\t5", "6\t6", "7\t7", 
    "8\t8", "9\t9", "10\t10", "11\t11", "12\t12", "13\t13", "14\t14", 
    "15\t15", "16\t16", "17\t17", "18\t18", "19\t19", "20\t20", "21\t21", 
    "22\t22", "23\t23", "24\t24", "25\t25", "26\t26"),
  filename
)
hashfile(filename)

Output:

  • Windows: 1de50dce6d5139f98a8e69d4d45d26ae7d32c64f
  • Linux: 3e6fbe383532f4312bd0f5c9f30976f64d00e9cc

Session info on Windows

Session info ──────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.2 (2018-12-20)
 os       Windows >= 8 x64            
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  Dutch_Belgium.1252          
 ctype    Dutch_Belgium.1252          
 tz       Europe/Paris                
 date     2019-08-14Packages ──────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.5.3)
 cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.3)
 crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.3)
 drat          0.1.4   2017-12-16 [1] CRAN (R 3.5.3)
 fortunes      1.5-4   2016-12-29 [1] CRAN (R 3.5.2)
 git2r       * 0.25.2  2019-03-19 [1] CRAN (R 3.5.3)
 rstudioapi    0.10    2019-03-19 [1] CRAN (R 3.5.3)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.3)
 withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.3)
 yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.2)

[1] C:/R/library
[2] C:/Program Files/R/R-3.5.2/library

Session info on Linux

Session info ──────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Ubuntu 18.04.3 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language nl:en                       
 collate  nl_NL.UTF-8                 
 ctype    nl_NL.UTF-8                 
 tz       Europe/Brussels             
 date     2019-08-14Packages ──────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.0)
 cli           1.1.0   2019-03-19 [2] CRAN (R 3.5.3)
 crayon        1.3.4   2017-09-16 [2] CRAN (R 3.5.3)
 drat          0.1.5   2019-03-28 [1] CRAN (R 3.6.0)
 fortunes      1.5-4   2016-12-29 [1] CRAN (R 3.6.0)
 git2r         0.26.1  2019-06-29 [1] CRAN (R 3.6.0)
 packrat       0.5.0   2018-11-14 [1] CRAN (R 3.6.0)
 rstudioapi    0.10    2019-03-19 [2] CRAN (R 3.5.3)
 sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 3.5.3)
 withr         2.1.2   2018-03-15 [2] CRAN (R 3.5.3)

[1] /home/thierry_onkelinx/R/x86_64-pc-linux-gnu-library/3.5
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
@stewid
Copy link
Member

stewid commented Aug 15, 2019

The reason you get a different hash between Linux and Windows is beacuse the file content is different in your example. When you use writeLines, it writes the line separator with a LF on Unix/Linux and CRLF on Windows, therefore, the hash is different.

If you rewrite the example to use writeChar instead to control the line endings, the hash should be identical between Linux and Windows.

library(git2r)
filename <- tempfile("test-file")
f <- file(filename, "wb")
writeChar(
    "x\ty\n1\t1\n2\t2\n3\t3\n4\t4\n5\t5\n6\t6\n7\t7\n8\t8\n9\t9\n10\t10\n11\t11\n12\t12\n13\t13\n14\t14\n15\t15\n16\t16\n17\t17\n18\t18\n19\t19\n20\t20\n21\t21\n22\t22\n23\t23\n24\t24\n25\t25\n26\t26\n",
    f,
    eos = NULL)
close(f)
hashfile(filename)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants