Message ID | 1481611195-105372-4-git-send-email-konrad.wilk@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Konrad Rzeszutek Wilk writes ("[PATCH v2 3/9] OssTest: Add target_dir_exists"): > We have target_file_exists but not an equivalant one for directories. > This adds it in and is used in the "ts-xen-build: Make {xen|}dist.tar.gz > only if $builddir/install/{$xen|}install" patch. Do you care about the distinction between a file and a directory ? IOW I don't understand why target_file_exists wouldn't do. If you think the word "file" in its name is confusing, please feel free to add a doc comment or to rename that function. Thanks, Ian.
On Tue, Dec 13, 2016 at 04:24:56PM +0000, Ian Jackson wrote: > Konrad Rzeszutek Wilk writes ("[PATCH v2 3/9] OssTest: Add target_dir_exists"): > > We have target_file_exists but not an equivalant one for directories. > > This adds it in and is used in the "ts-xen-build: Make {xen|}dist.tar.gz > > only if $builddir/install/{$xen|}install" patch. > > Do you care about the distinction between a file and a directory ? Yes. I just need to mke sure that the directory exists, while there may be multiple files (in it). > IOW I don't understand why target_file_exists wouldn't do. > > If you think the word "file" in its name is confusing, please feel > free to add a doc comment or to rename that function. The functions are pretty similar. The file one does 'test -e' while this one does 'test -d'. > > Thanks, > Ian.
Konrad Rzeszutek Wilk writes ("Re: [PATCH v2 3/9] OssTest: Add target_dir_exists"): > On Tue, Dec 13, 2016 at 04:24:56PM +0000, Ian Jackson wrote: > > Konrad Rzeszutek Wilk writes ("[PATCH v2 3/9] OssTest: Add target_dir_exists"): > > > We have target_file_exists but not an equivalant one for directories. > > > This adds it in and is used in the "ts-xen-build: Make {xen|}dist.tar.gz > > > only if $builddir/install/{$xen|}install" patch. > > > > Do you care about the distinction between a file and a directory ? > > Yes. I just need to mke sure that the directory exists, while there > may be multiple files (in it). No, that wasn't what I meant. I meant: do you actually need to test whether the name you are giving to the test refers to a directory, or simply to tell whether it exists ? The distinction is only relevant if the object might also non-erroneously be a file. (If it's erroneously a file, and you proceed as if it's a directory, you will crash later.) > > IOW I don't understand why target_file_exists wouldn't do. > > > > If you think the word "file" in its name is confusing, please feel > > free to add a doc comment or to rename that function. > > The functions are pretty similar. The file one does 'test -e' while > this one does 'test -d'. test -e tests for general existence of things. I think test -e would do for you in this case. Thanks Ian.
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 2486320..9377af1 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -62,6 +62,7 @@ BEGIN { target_put_guest_image target_editfile target_editfile_cancel target_fetchurl target_editfile_root target_file_exists + target_dir_exists target_editfile_kvp_replace target_run_apt target_install_packages target_install_packages_norec @@ -518,6 +519,14 @@ sub target_file_exists ($$) { die "$rfile $out ?"; } +sub target_dir_exists ($$) { + my ($ho,$rfile) = @_; + my $out= target_cmd_output($ho, "if test -d $rfile; then echo y; fi"); + return 1 if $out =~ m/^y$/; + return 0 if $out !~ m/\S/; + die "$rfile $out ?"; +} + sub next_unique_name ($) { my ($fnref) = @_; my $num = $$fnref =~ s/\+([1-9]\d*)$// ? $1 : 0;
We have target_file_exists but not an equivalant one for directories. This adds it in and is used in the "ts-xen-build: Make {xen|}dist.tar.gz only if $builddir/install/{$xen|}install" patch. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- v2: New patch. --- Osstest/TestSupport.pm | 9 +++++++++ 1 file changed, 9 insertions(+)