diff mbox

[v2,3/9] OssTest: Add target_dir_exists

Message ID 1481611195-105372-4-git-send-email-konrad.wilk@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk Dec. 13, 2016, 6:39 a.m. UTC
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(+)

Comments

Ian Jackson Dec. 13, 2016, 4:24 p.m. UTC | #1
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.
Konrad Rzeszutek Wilk May 17, 2017, 8:59 p.m. UTC | #2
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.
Ian Jackson May 18, 2017, 4:50 p.m. UTC | #3
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 mbox

Patch

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;