Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 528269 - Gracefully handle file names that are too long
  • Loading branch information
mrennie committed Dec 7, 2017
1 parent 04e4b91 commit b246edc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
17 changes: 12 additions & 5 deletions modules/orionode/lib/file.js
Expand Up @@ -208,11 +208,15 @@ module.exports = function(options) {
});
}
return fileUtil.withStatsAndETag(file.path, function(error, stats, etag) {
if (error && error.code === 'ENOENT') {
if(typeof readIfExists === 'boolean' && readIfExists) {
api.sendStatus(204, res);
} else {
writeError(404, res, 'File not found: ' + rest);
if (error) {
if(error.code === 'ENOENT') {
if(typeof readIfExists === 'boolean' && readIfExists) {
api.sendStatus(204, res);
} else {
writeError(404, res, 'File not found: ' + rest);
}
} else if(error.code === 'ENAMETOOLONG') {
writeError(400, res, 'The given file path is too long: '+file.path);
}
} else if (error) {
writeError(500, res, error);
Expand Down Expand Up @@ -269,6 +273,9 @@ module.exports = function(options) {
});
}
return fileUtil.withStatsAndETag(file.path, function(error, stats, etag) {
if(error && error.code === 'ENAMETOOLONG') {
return api.writeError(400, res);
}
if(stats && stats.isDirectory()) {
return api.writeError(400, res, "Cannot write contents to a folder: "+file.path);
}
Expand Down
12 changes: 9 additions & 3 deletions modules/orionode/lib/fileUtil.js
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2016, 2017 IBM Corporation and others.
* Copyright (c) 2012, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Expand Down Expand Up @@ -620,8 +620,14 @@ exports.deleteFile = function(req, file, matchEtag, callback) {
}
done(error);
}
if (error && error.code === 'ENOENT') {
return checkMetadata();
if (error) {
if(error.code === 'ENOENT') {
return checkMetadata();
} else if(error.code === 'ENAMETOOLONG') {
var err = new Error("Requested file path is too long");
err.code = 400;
return callback(err);
}
} else if (matchEtag && matchEtag !== etag) {
var err = new Error("");
err.code = 412;
Expand Down

0 comments on commit b246edc

Please sign in to comment.