Merge pull request #654 from Algunenano/ogr_length

Fix an ogr2ogr export issue when the temporal name is too big
This commit is contained in:
Raúl Marín 2020-05-14 12:47:17 +02:00 committed by GitHub
commit 5e611f8826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -4,6 +4,7 @@
Released 2020-mm-dd
- Updated allowed list of custom headers with the ones for metrics
- Fix an ogr2ogr export issue when the temporal name is too big [`653`](https://github.com/CartoDB/CartoDB-SQL-API/issues/653).
## 5.0.1

View File

@ -45,6 +45,11 @@ OgrFormat.prototype = {
var hash = crypto.createHash('md5');
hash.update(data);
return hash.digest('hex');
},
limitPathname: function (pathname) {
if (pathname.length < 128) { return pathname; }
return crypto.createHash('sha256').update(pathname).digest('hex');
}
};
@ -230,14 +235,14 @@ OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
var layername = options.filename;
var tmpdir = global.settings.tmpDir || '/tmp';
var reqKey = [
var reqKey = this.limitPathname([
fmt,
dbname,
userId,
gcol,
this.generateMD5(layername),
this.generateMD5(sql)
].concat(skipfields).join(':');
].concat(skipfields).join(':'));
var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey;
var dumpfile = outdirpath + ':cartodb-query.' + ext;

View File

@ -37,7 +37,7 @@ ShpFormat.prototype.toSHP = function (options, callback) {
var zip = global.settings.zipCommand || 'zip';
var zipOptions = '-qrj';
var tmpdir = global.settings.tmpDir || '/tmp';
var reqKey = ['shp', dbname, userId, gcol, this.generateMD5(sql)].concat(skipfields).join(':');
var reqKey = this.limitPathname(['shp', dbname, userId, gcol, this.generateMD5(sql)].concat(skipfields).join(':'));
var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey;
var zipfile = outdirpath + '.zip';
var shapefile = outdirpath + '/' + filename + '.shp';

View File

@ -31,6 +31,26 @@ describe('geopackage query', function () {
});
});
it('works with a long list of skipfields', function (done) {
const longUrl = baseUrl + `&skipfields=the_geom_webmercator,${'a'.repeat(300)}`;
assert.response(server, {
url: longUrl,
headers: { host: 'vizzuality.cartodb.com' },
method: 'GET'
}, { }, function (err, res) {
assert.ifError(err);
assert.strictEqual(res.statusCode, 200, res.body);
assert.strictEqual(res.headers['content-type'], 'application/x-sqlite3; charset=utf-8');
assert.notEqual(res.headers['content-disposition'].indexOf(tableName + '.gpkg'), -1);
var db = new sqlite.Database(':memory:', res.body);
var qr = db.get('PRAGMA database_list', function (err) {
assert.strictEqual(err, null);
done();
});
assert.notEqual(qr, undefined);
});
});
it('gets database and geopackage schema', function (done) {
assert.response(server, {
url: baseUrl,