FileIO.toFile does not truncate existing file

16 views
Skip to first unread message

Enno

unread,
Apr 21, 2017, 9:37:24 AM4/21/17
to Akka User List
Hi Hakkars,

The file my stream created started to look rather funny so I had to dig a bit.

The API docs for FileIO.toFile state it "Overwrites existing files by default.", but that becomes a bit to literally with the default options.

  def toPath(f: Path, options: Set[StandardOpenOption] = Set(WRITE, CREATE))

For an existing file with options WRITE, CREATE the new content will overwrite the file's content from the file's start, but not truncate the old contents. So in case less content is written in later runs the old content will follow the new content. 

Wouldn't it be more intuitive (and more according to the docs) to use WRITE, CREATE, TRUNCATE_EXISTING as default options?

Cheers,
Enno.

Patrik Nordwall

unread,
Apr 21, 2017, 9:39:32 AM4/21/17
to akka...@googlegroups.com
Wow, not truncating would be very confusing. Please open a PR.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Akka Tech Lead
Lightbend -  Reactive apps on the JVM
Twitter: @patriknw

Konrad Malawski

unread,
Apr 21, 2017, 10:57:24 AM4/21/17
to akka...@googlegroups.com, Patrik Nordwall
Great catch, you're absolutely right. Please open a PR, thanks!

-- 
Konrad Malawski
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

Enno

unread,
Apr 21, 2017, 4:01:52 PM4/21/17
to Akka User List
Please consider PR #22772

Cheers,
Enno.


Am Freitag, 21. April 2017 15:39:32 UTC+2 schrieb Patrik Nordwall:
Wow, not truncating would be very confusing. Please open a PR.
On Fri, Apr 21, 2017 at 3:36 PM, Enno <enno....@gmail.com> wrote:
Hi Hakkars,

The file my stream created started to look rather funny so I had to dig a bit.

The API docs for FileIO.toFile state it "Overwrites existing files by default.", but that becomes a bit to literally with the default options.

  def toPath(f: Path, options: Set[StandardOpenOption] = Set(WRITE, CREATE))

For an existing file with options WRITE, CREATE the new content will overwrite the file's content from the file's start, but not truncate the old contents. So in case less content is written in later runs the old content will follow the new content. 

Wouldn't it be more intuitive (and more according to the docs) to use WRITE, CREATE, TRUNCATE_EXISTING as default options?

Cheers,
Enno.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages