julianpeeters / avrohugger

Generate Scala case class definitions from Avro schemas
Apache License 2.0
201 stars 120 forks source link

Fix #147 - Use a separate temp directory #148

Closed timo-schmid closed 2 years ago

timo-schmid commented 3 years ago

Problem Description

We're having an issue with deleted files after the build with sbt-avrohugger. It seems, after the build some directories get deleted that shouldn't.

From what I could understand, the original path before a49e5f6 was relative (target). Now in our build, we pass this directory absolute, eg. (/path/to/build).

The issue we encountered was the following: The method deleteTemps deletes all files in the penultimate file of this path (in above example /path/to), that have no children - this seems to apply to all files as well as empty directories

Description of changes

I've taken the following actions, to avoid this in the future:

Steps to reproduce this issue:

1. Create the temporary directory structure

mkdir -p /tmp/poc/java_tmp
touch /tmp/poc/foo
touch /tmp/poc/bar
touch /tmp/poc/baz
find /tmp/poc
# /tmp/poc
# /tmp/poc/java_tmp
# /tmp/poc/foo
# /tmp/poc/baz
# /tmp/poc/bar

2. Run the build (for example with sbt-avrohugger 2.0.0-RC24)

SBT_OPTS="-Djava.io.tmpdir=/tmp/poc/java_tmp" sbt clean compile

3. Verify the outcome

find /tmp/poc
# /tmp/poc
# /tmp/poc/java_tmp
# /tmp/poc/java_tmp/my
# /tmp/poc/java_tmp/my/namespace
# /tmp/poc/java_tmp/my/namespace/name

Note that foo, bar and baz have been deleted.

Workaround

In my case I downgraded to 2.0.0-RC15, which didn't have this issue yet it seems.

Final note

I would urge users not to use the versions from 2.0.0-RC16 up to 2.0.0-RC24, because they can actually damage your system (if the permissions allow it). For example, if I were to set -Djava.io.tmpdir=/home/myuser/.java_tmp it could wipe out my home directory.

Just a heads up!

julianpeeters commented 2 years ago

Thank you very much for submitting this. Merged and published in avrohugger 1.0.0-RC26 and sbt-avrohugger 2.0.0-RC26