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

validate does not work correctly when the path name contains a space #381

Closed
msbentley opened this issue Jul 30, 2021 · 8 comments
Closed
Assignees
Labels
B12.0 bug Something isn't working s.medium

Comments

@msbentley
Copy link

🐛 Describe the bug

When the containing path to a PDS4 product contains a space (even if validate is executed within this directory), validate fails with an error related to the detection of the file size.

📜 To Reproduce

Steps to reproduce the behavior:

  1. Great a directory with a space (e.g. "a test")
  2. Add a PDS4 product to this directory
  3. Run validate from within this directory

🕵️ Expected behavior

validate executed normally

📚 Version of Software Used

validate 2.0.7

🩺 Test Data / Additional context

PDS Validate Tool Report

Configuration:
   Version                       2.0.7
   Date                          2021-07-30T13:46:42Z

Parameters:
   Targets                       [file:/home/mbentley/Desktop/a%20test/]
   User Specified Catalogs       [/home/mbentley/Dropbox/work/bepi/xml_catalog_rewrite.xml]
   Severity Level                WARNING
   Recurse Directories           true
   File Filters Used             [*.xml, *.XML]
   Data Content Validation       on
   Product Level Validation      on
   Max Errors                    100000
   Registered Contexts File      /home/mbentley/Dropbox/software/pds/validate-2.0.7/resources/registered_context_products.json
   Non Registered Contexts File  /home/mbentley/Dropbox/work/bepi/repos/psa.pds4/psa/local_context_products.json



Product Level Validation Results

  PASS: gov.nasa.pds.validate.ValidateLauncher
      WARNING  [warning.product_not_registered]   Non-registered context products should only be used during archive development. All context products must be registered for a valid, released archive bundle. 
        1 product validation(s) completed

  FAIL: file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.xml
      ERROR  [error.label.filesize_mismatch]   Generated filesize '0' does not match supplied filesize '256000' in the product label for 'file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc'
      WARNING  [error.label.filesize_mismatch]   Object-defined size+offset is greater than actual file size in data file: 51200 > 0 file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc
      WARNING  [error.label.filesize_mismatch]   Object-defined size+offset is greater than actual file size in data file: 102400 > 0 file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc
      WARNING  [error.label.filesize_mismatch]   Object-defined size+offset is greater than actual file size in data file: 153600 > 0 file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc
      WARNING  [error.label.filesize_mismatch]   Object-defined size+offset is greater than actual file size in data file: 204800 > 0 file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc
      WARNING  [error.label.filesize_mismatch]   Object-defined size+offset is greater than actual file size in data file: 256000 > 0 file:/home/mbentley/Desktop/a%20test/acs_cal_sc_tir_20180421T204122-20180421T223903-1830-1-occ-791286.spc
        2 product validation(s) completed

Summary:

  1 error(s)
  6 warning(s)

  Product Validation Summary:
    1          product(s) passed
    1          product(s) failed
    0          product(s) skipped

  Referential Integrity Check Summary:
    0          check(s) passed
    0          check(s) failed
    0          check(s) skipped

  Message Types:
    6            error.label.filesize_mismatch
    1            warning.product_not_registered

End of Report
Completed execution in 5478 ms

🖥 System Info

  • OS: seen in both ubuntu and MacOS

🦄 Related requirements

⚙️ Engineering Details

@msbentley msbentley added bug Something isn't working needs:triage labels Jul 30, 2021
@dcoia740
Copy link

Thanks @msbentley :)

@qchaupds
Copy link
Contributor

qchaupds commented Aug 4, 2021

We think the bug is here. The Java File class doesn't play well with the "%20" so it needs the actual space in the name.

{pds-dev3.jpl.nasa.gov}/home/qchau/sandbox/validate 107 % git diff src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java
diff --git a/src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java b/src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java
index 9b60590..bead5b9 100644
--- a/src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java
+++ b/src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java
@@ -33,10 +33,19 @@ public class FileSizesUtil {
 
       if (url.getProtocol().equals("file")) {
             long fileSize = -1;
-            LOG.debug("getExternalFilesize:url,fileSize {}",url,fileSize);
-            File file = new File(url.getPath());
+            LOG.debug("getExternalFilesize:url,fileSize {},{}",url,fileSize);
+            LOG.debug("getExternalFilesize:afor:path [{}]",url.getPath());
+            // For some strange reason, the File class does not handle well the "%20" in the name.  It needs to be an actual space.
+            String actualPath = url.getPath().replace("%20"," ");  // Replace the "%20" with one space " "
+            LOG.debug("getExternalFilesize:after:path [{}]",actualPath);
+            File file = new File(actualPath);
+            if (!file.exists()) {
+                LOG.error("getExternalFilesize:Cannot find file [{}]",actualPath);
+            } else {
+                LOG.debug("getExternalFilesize:File exist [{}]",actualPath);
+            }
             fileSize = file.length();
-           LOG.debug("getExternalFilesize:url,fileSize {}",url,fileSize);
+            LOG.debug("getExternalFilesize:url,fileSize {},{}",url,fileSize);
             return(fileSize);
       } else {
         URLConnection conn = null;

Will check the code in at next opportunity.

qchaupds pushed a commit that referenced this issue Aug 5, 2021
1. Add test resource :src/test/resources/github381
2. Fix bug by relacing "%20" with " " if the directory name contains a space: src/main/java/gov/nasa/pds/tools/util/FileSizesUtil.java

Refs:

#381 validate does not work correctly when the path name contains a space
jordanpadams added a commit that referenced this issue Aug 9, 2021
Fix bug when directory name contains a space
@jordanpadams
Copy link
Member

resolved per #387

@msbentley
Copy link
Author

Hi @jordanpadams @qchaupds whilst this resolves the issue for me on linux, @dcoia740 is still facing issues on the Mac - could you confirm if the fix was tested there, and if it works OK? Thanks!

@dcoia740
Copy link

For the record, I'm on Catalina 10.15.7, java version "14.0.2"

@jordanpadams
Copy link
Member

@msbentley sorry. looks like we did not. new ticket created and added to the top of the stack.

@msbentley
Copy link
Author

Great, thanks @jordanpadams

@dcoia740
Copy link

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B12.0 bug Something isn't working s.medium
Projects
None yet
Development

No branches or pull requests

4 participants