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

Check if tempPath Exists Before Unlinking #27

Merged
merged 1 commit into from Feb 14, 2019
Merged

Check if tempPath Exists Before Unlinking #27

merged 1 commit into from Feb 14, 2019

Conversation

ghost
Copy link

@ghost ghost commented Feb 12, 2019

Do we need to move L18 into the if conditional?

For example:

if (fs.existsSync(tempPath)) {
    delete this._downloads[tileKey];
    fs.unlinkSync(tempPath);
}

@ghost
Copy link
Author

ghost commented Feb 12, 2019

References: #16

@ghost
Copy link
Author

ghost commented Feb 12, 2019

Upon further inspection, it would appear this is an issue with L6 in hgt.js:

var fd = fs.openSync(path, 'r'),

@ghost
Copy link
Author

ghost commented Feb 12, 2019

Could the error occur because the coords N21, E122 are in the ocean where there is probably no saved data or does the module account for this?

The errors I'm getting:

{ [Error: ENOENT: no such file or directory, open '/var/folders/bf/n6q0w74n6dvct5w16mpj2d_h0000gn/T/F51.zip']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/folders/bf/n6q0w74n6dvct5w16mpj2d_h0000gn/T/F51.zip' }

And more commonly:

{ Error: ENOENT: no such file or directory, open '/Users/alex/rw/ggr-navigation-cloud/functions/shared/util/data/N21E122.hgt'
    at Object.openSync (fs.js:436:3)
    at new Hgt (/Users/alex/rw/ggr-navigation-cloud/node_modules/node-hgt/src/hgt.js:6:17)
    at /Users/alex/rw/ggr-navigation-cloud/node_modules/node-hgt/src/load-tile.js:28:35
    at /Users/alex/rw/ggr-navigation-cloud/node_modules/node-hgt/src/imagico.js:50:9
    at tryCallOne (/Users/alex/rw/ggr-navigation-cloud/node_modules/promise/lib/core.js:37:12)
    at /Users/alex/rw/ggr-navigation-cloud/node_modules/promise/lib/core.js:123:15
    at flush (/Users/alex/rw/ggr-navigation-cloud/node_modules/asap/raw.js:50:29)
    at process._tickCallback (internal/process/next_tick.js:61:11)
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path:
   '/Users/alex/rw/ggr-navigation-cloud/functions/shared/util/data/N21E122.hgt' }

Code Ref:

const path = require('path')
const {SyncTileSet} = require('../functions/shared/util/ElevationUtils');

function prepareElevationData() {
  const p = path.resolve(__dirname, '../functions/shared/util/data/')
  console.log('Downloading elevation data to path:', p)
  const tileset = new SyncTileSet(p, [21, 119], [26, 123], function(err) {
    if (err) {
      console.log('There was an error retrieving the latest elevation data, please try again.')
      console.error(err)
      return
    }

    console.log('Elevation data successfully downloaded.')
  })
}

prepareElevationData()

@ghost
Copy link
Author

ghost commented Feb 12, 2019

Stepping through the code I've found the following:

Requesting LatLon[26, 122] returns the following URL:

http://www.imagico.de/map/dem_json.php?date=&lon=122&lat=26&lonE=122&latE=26&vf=1

Which returns the response:

[{"name":"G51.zip","title":"","link":"http:\/\/www.viewfinderpanoramas.org\/dem3\/G51.zip","date":"2012-06-08","lon_start":"120","lat_start":"24","lon_end":"126","lat_end":"28","type":"2"}]

Downloading the link from the above response, I get a zip file that does not include N26E122. It looks like the module is failing when it cannot find a file.

@perliedman perliedman merged commit 8974c41 into perliedman:master Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants