JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.54k stars 5.47k forks source link

cp copy over existing file #8698

Closed XilinJia closed 9 years ago

XilinJia commented 9 years ago

It does not remove the target file first, but simply writes content on top of it and keeps the remaining contents. Look at the following example on Xubuntu 14.04:

$ more test1.txt
asdasfd
sfasf
asdad
sdsdg gsdg
$ more test2.txt
dfs
sdfs
sdffsdfsgs sdgsgsdgds gsdgs
sdgs sdgsdsdh

$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.1 (2014-09-21 21:30 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
|__/                   |  x86_64-linux-gnu

julia> cp("test1.txt", "test2.txt")
File("test2.txt",false,-1)

julia> quit()

$ more test2.txt
asdasfd
sfasf
asdad
sdsdg gsdggsdgs
sdgs sdgsdsdh

Edit: ivarne (added quotes)

ivarne commented 9 years ago

Previously reported on julia-users. Thanks for opening an issue here.

Seems to be a regression caused by #4733. cc @lifeissweetgood

stevengj commented 9 years ago

Seems like this line should have used the O_TRUNC flag.