-
Notifications
You must be signed in to change notification settings - Fork 14
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
FileWriter: use atomic write #202
Conversation
This requires testing obviously |
src/main/perl/FileWriter.pm
Outdated
$self->verbose ("Changes to $filename:"); | ||
$self->report ($diff); | ||
} | ||
|
||
if (*$self->{options}->{noaction}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this test the right way round? i.e. this seems to be the block that's executed when noaction is true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably. but this commit is already outdated
src/main/perl/FileWriter.pm
Outdated
$modified = 1; | ||
}; | ||
if ($@) { | ||
$self->verbose("AtomicWrite gave error: $@"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only verbose because throw_error takes care of generating the actual error? In which case debug would be more appropriate to avoid the duplicate message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with verbose logging to file, anything interesting should be logged; and a failure to write is interesting enough imho.
also lots of code doesn't do any exception handling with FileWriter; at least in this case with verbose_logfile there's another trace where the error came from.
it's "only" verbose because we can hardly log an error here if we try to be as backwards compatible as possible (LC::Check::file
also didn't report an error). the thow_error
is sort-of legacy usage (afai understand, we want to die
or croak
in the some near future).
it might make sense to add another option to control to report an error here (default could even be true)
use version; | ||
|
||
# Always recent enough | ||
our $VERSION = 10000.0.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should declare here the API version we are mocking. Then if a later version changes, we get a failure and get reminded to go and check we updated the mock to match the behaviour of the real thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
=head1 SYNOPSIS | ||
|
||
This is a backup module for File::AtomicWrite. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/backup/mock/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/test/perl/modules/filetools.pm
Outdated
my $fn = shift; | ||
my $dir = dirname($fn); | ||
mkpath $dir if ! -d $dir; | ||
open(FH, ">$fn"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bare filehandles and two element open is considered dangerous. Please use open(my $fh, ">", "$fn");
as per the Perl Best Practice Book.
src/test/perl/modules/filetools.pm
Outdated
|
||
sub readfile | ||
{ | ||
open(FH, shift); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/test/perl/modules/filetools.pm
Outdated
mkpath $dir if ! -d $dir; | ||
open(FH, ">$fn"); | ||
print FH (shift || "ok"); | ||
close(FH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither open() nor close() do any error handling which is generally bad, although given this is a unit test helper function, perhaps it's not bad in this specific case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. now die
s with proper message
1756d4d
to
6c070b8
Compare
@ned21 first round of remarks addressed 😄 |
6c070b8
to
da317a2
Compare
88ca493
to
519ea6f
Compare
src/test/perl/modules/filetools.pm
Outdated
@@ -0,0 +1,33 @@ | |||
package filetools; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch to new unittest Filetools module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to switch to new unittest Filetools module.
src/test/perl/modules/filetools.pm
Outdated
@@ -0,0 +1,33 @@ | |||
package filetools; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to switch to new unittest Filetools module.
I'd like to test it to see in particular if it fixes quattor/maven-tools#139. Could we get the dependencies in quattor externals repo? |
…d only write when needed
@ned21 this is not blocking the spma PR at all, the fix is just to handle the failure in cleaner way, it doesn 't fix the failure itself |
…ence before testing it has a is_verbose method (Fixes quattor#223)
@ned21 message updated |
I'm good with this PR, waiting on @jrha to confirm the changes he requested have been made. |
rpms added to externals repo |
Requires #204 and #206
Fixes #148
Fixes #223
Also fixes #189
File::AtomicWrite
requires 0.18, rpm can be build usingcpanspec -b --packager quattor File::AtomicWrite --force