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

FileWriter: use atomic write #202

Merged
merged 11 commits into from
Mar 29, 2017
Merged

FileWriter: use atomic write #202

merged 11 commits into from
Mar 29, 2017

Conversation

stdweird
Copy link
Member

@stdweird stdweird commented Nov 26, 2016

Requires #204 and #206
Fixes #148
Fixes #223
Also fixes #189

File::AtomicWrite requires 0.18, rpm can be build using cpanspec -b --packager quattor File::AtomicWrite --force

@stdweird stdweird added this to the 16.12 milestone Nov 26, 2016
@stdweird
Copy link
Member Author

This requires testing obviously

$self->verbose ("Changes to $filename:");
$self->report ($diff);
}

if (*$self->{options}->{noaction}) {
Copy link
Contributor

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?

Copy link
Member Author

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

$modified = 1;
};
if ($@) {
$self->verbose("AtomicWrite gave error: $@");
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/backup/mock/ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

my $fn = shift;
my $dir = dirname($fn);
mkpath $dir if ! -d $dir;
open(FH, ">$fn");
Copy link
Contributor

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.


sub readfile
{
open(FH, shift);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

mkpath $dir if ! -d $dir;
open(FH, ">$fn");
print FH (shift || "ok");
close(FH);
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. now dies with proper message

@stdweird
Copy link
Member Author

@ned21 first round of remarks addressed 😄

@@ -0,0 +1,33 @@
package filetools;
Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrha @ned21 hmm, i can't request changes on my own PR. can you help me not to forget 😄

Copy link
Member

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.

@@ -0,0 +1,33 @@
package filetools;
Copy link
Member

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.

@stdweird
Copy link
Member Author

@jrha Filetools used
@ned21 what changes do you still need?

@jouvin
Copy link
Contributor

jouvin commented Mar 19, 2017

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?

@stdweird
Copy link
Member Author

@jouvin i mailed them to you and @jrha lasty week 😄

@stdweird
Copy link
Member Author

@ned21 i added another commit to fix #223

@ned21
Copy link
Contributor

ned21 commented Mar 21, 2017

The fix to #223 is 2fee451? Can the "Fixes #223" line be added to the commit log? Also any chance of a separate PR in case this doesn't make the cut for 17.3? Then we can get the spma change merged.

@stdweird
Copy link
Member Author

@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)
@stdweird
Copy link
Member Author

@ned21 message updated

@ned21
Copy link
Contributor

ned21 commented Mar 23, 2017

I'm good with this PR, waiting on @jrha to confirm the changes he requested have been made.

@stdweird
Copy link
Member Author

rpms added to externals repo

@jrha jrha merged commit 4ad8514 into quattor:master Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants