-
Notifications
You must be signed in to change notification settings - Fork 77
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
add a new command opm clean
#22
Conversation
to delete folder and .gz file created by opm build or opm upload
@Pronan You patch looks wrong to me. I don't think your code even runs: $ perl -c bin/opm
Global symbol "$root_dir" requires explicit package name (did you forget to declare "my $root_dir"?) at bin/opm line 2203.
Global symbol "$root_dir" requires explicit package name (did you forget to declare "my $root_dir"?) at bin/opm line 2204. |
fully tested and passed
@agentzh Sorry, chun ge, I fixed it. This time this commit is fully tested and passed. |
It only cleans the latest. Should it clean the previously created versions as well? |
@bungle do you mean change |
@Pronan, I mean that maybe that should be considered as well. Not sure if that should be a default or should we introduce a command line argument. # clean latest / current or all?
opm dist-clean
# clean current
opm dist-clean current # or
opm dist-clean --current # or
opm dist-clean -c
# clean all
opm dist-clean all # or
opm dist-clean --all # or
opm dist-clean -a Or something? Also I'm not sure if it should be called |
@Pronan Sorry, I changed my mind a bit. It seems like I agree that I think it's good enough to just cleanup whatever looks like our leftover. Basically we can iterate through the current working directory, checking each file or directory, looking for
And remove them all. To iterate through the cwd, we can just use the What's your opinion? |
e.g. if your package name is `lua-resty-foo`, now with option `dist`, i.e. `opm clean dist` will delete all folders like `lua-resty-foo-1.0` and files like `lua-resty-foo-1.0.tar.gz`
@agentzh hello, chun ge. I agree with you.PR is tested and passed with your regex pattern. |
opm dist-clean
opm clean
sorry, I've tested several version, and commited a wrong vesion. this one is correct
opendir(my $dh, './') || die "Can't opendir"; | ||
my @dots = readdir($dh); | ||
foreach my $x (@dots) { | ||
if(-d $x){ |
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.
Style: need a space after if
and also before {
. Please keep the coding style consistent with the rest of the code base. Thanks!
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
shell "rm -rf $x"; | ||
say 'delete:',$x; | ||
} | ||
}else{ |
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.
Style: need a space before and after else
.
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
if(-d $x){ | ||
if ($x =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*$/){ | ||
shell "rm -rf $x"; | ||
say 'delete:',$x; |
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.
Better avoid using say
to be consistent with the rest of the code base. Also need a space after the comma (,
).
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
my $data = read_ini($dist_file); | ||
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; | ||
opendir(my $dh, './') || die "Can't opendir"; |
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.
Error message in case of opendir
failures is not descriptive enough. Please see similar places in this file for examples.
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
if (@_ == 0) { | ||
err "no clean option specified.\n"; | ||
} | ||
if ($_[0] eq 'dist') { |
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.
Style: 2 spaces before eq
while only one is needed.
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.
Also, need a blank line before this if
statement.
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.
} | ||
} | ||
} | ||
closedir $dh; |
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.
Need error handling when closedir
returns an 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.
done
} | ||
}else{ | ||
if ($x =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*\.tar\.gz$/){ | ||
shell "rm -rf $x"; |
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.
We should use the Perl builtin function unlink
to remove a single file. rm -rf
is overkill here.
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
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; | ||
opendir(my $dh, './') || die "Can't opendir"; | ||
my @dots = readdir($dh); |
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.
dots
is a bad name. Maybe entities
is better?
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.
my $dist_name = $default_sec->{name}; | ||
opendir(my $dh, './') || die "Can't opendir"; | ||
my @dots = readdir($dh); | ||
foreach my $x (@dots) { |
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.
x
is a bad name. we need more descriptive names like entity
, I think.
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.
Oh, BTW, I think you can just use for
here instead of foreach
.
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
} | ||
closedir $dh; | ||
}else{ | ||
err "invalid clean option: ".$_[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.
Again, we need spaces around the .
operator. I think the error message unrecognized argument for clean
is better. Also, we should give a list of recognized clean arguments here as well.
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
Thanks for your work on this! Please address the issues in my latest round of review :) Thanks! |
foreach my $x (@dots) { | ||
if(-d $x){ | ||
if ($x =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*$/){ | ||
shell "rm -rf $x"; |
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.
Oh, forgot to mention that, we also need to test if there is an dist.ini
file in this directory before removing it recursively. rm -rf
is scary and we can never be too cautious here ;)
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.
Do you mean if there is a dist.ini
file in it, it should not be removed even if it matches the regex?
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 mean, if there is no dist.ini
in a directory, then we should not remove it. Since the dist directory generated by opm
must have a dist.ini
file in it (unless there is a failure in the middle of the previous opm build
run).
And...we also need to update the usage text in the program as well as the documentation for this new feature BTW :) |
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.
hello, chun ge.
} | ||
closedir $dh; | ||
}else{ | ||
err "invalid clean option: ".$_[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.
done
if (@_ == 0) { | ||
err "no clean option specified.\n"; | ||
} | ||
if ($_[0] eq 'dist') { |
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.
my $dist_file = "dist.ini"; | ||
my $data = read_ini($dist_file); | ||
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; |
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.
a little hard for me. wait
my $data = read_ini($dist_file); | ||
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; | ||
opendir(my $dh, './') || die "Can't opendir"; |
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
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; | ||
opendir(my $dh, './') || die "Can't opendir"; | ||
my @dots = readdir($dh); |
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.
} | ||
}else{ | ||
if ($x =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*\.tar\.gz$/){ | ||
shell "rm -rf $x"; |
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
} | ||
} | ||
} | ||
closedir $dh; |
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
} | ||
} | ||
closedir $dh; | ||
}else{ |
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
foreach my $x (@dots) { | ||
if(-d $x){ | ||
if ($x =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*$/){ | ||
shell "rm -rf $x"; |
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.
Do you mean if there is a dist.ini
file in it, it should not be removed even if it matches the regex?
my $dist_file = "dist.ini"; | ||
my $data = read_ini($dist_file); | ||
my $default_sec = $data->{default}; | ||
my $dist_name = $default_sec->{name}; |
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.
name
is a varible not a string literal, right? but I can't find where it is defined in do_build
.
@Pronan |
@agentzh Hello, Spring big brother, all done and test passed. |
} | ||
} | ||
closedir $dh | ||
or err "failed to close directory $dh!\n"; |
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.
We usually do not use !
at the end of our error string messages. Instead, you should use the special variable $!
here to output the system error string for the failed closedir
operation.
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
my @valid_options = ('dist'); | ||
|
||
if (@_ == 0) { | ||
err "no clean option specified.\n"; |
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 "dist" is a clean argument instead of an option. In the CLI terminology, options are usually something like --cwd
and --help
.
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
{ | ||
err "$dist_file: bad dist name: $dist_name\n"; | ||
} | ||
opendir(my $dh, './') |
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.
Need a blank line after the if
statement block.
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
err "$dist_file: bad dist name: $dist_name\n"; | ||
} | ||
opendir(my $dh, './') | ||
or err "failed to open directory './'!\n"; |
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.
We need to use : $!
instead of !
here. See other similar places. Be careful ;)
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
{ | ||
err "$dist_file: bad dist name: $dist_name\n"; | ||
} | ||
opendir(my $dh, './') |
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.
./
looks strange to me. You can just use .
here.
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
|
||
if (-e "$entity/dist.ini") { | ||
shell "rm -rf $entity"; | ||
print "delete folder: $entity\n"; |
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.
"delete" => "removed",
"folder" => "directory",
":" => ""
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
|
||
if ($entity =~ /^\Q$dist_name\E-[.\w]*\d[.\w]*\.tar\.gz$/) { | ||
unlink $entity; | ||
print "delete file: $entity\n"; |
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.
"delete" => "removed"
": " => ""
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
} | ||
|
||
if (length $dist_name < 3 | ||
|| $dist_name =~ /[^-\w]|^(?:nginx|luajit|resty|openresty|opm|restydoc.*|ngx_.*|.*-nginx-module)$/i) |
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.
Because this check is also used elsewhere. Maybe we should introduce a small Perl sub to avoid code duplication here? Like sub is_valid_dist_name
?
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
@@ -2195,6 +2198,57 @@ sub rebase_path ($$$) { | |||
return undef; | |||
} | |||
|
|||
sub do_clean { | |||
my @valid_options = ('dist'); |
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.
We won't have many different kinds of arguments, especially when we only have one right now. No need to introduce a Perl array here. It is just referenced once and simply adds line noises IMHO :)
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
closedir $dh | ||
or err "failed to close directory $dh!\n"; | ||
} else { | ||
err "unrecognized argument for clean: $_[0]. recognized clean arguments are: " . join(", ", @valid_options); |
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.
This line exceeds 80 columns a lot, I'm afraid ;)
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
Hello, chun ge. All done but I'm not sure how to merge my two PR so I did nothing for that. |
@agentzh hello, Should I do this in local computer or just on github webpage? I clone my fork |
@Pronan You do |
@Pronan Do not use GitHub's web UI to make changes. That tends to suck a lot. |
@agentzh Saddly, I was using github web UI to make changes.It sucks. Now I'm working on local branch. |
cool. |
This patch has been updated and merged with #26 to master. |
to delete folder and .gz file created by opm build or opm upload