Skip to content

Commit

Permalink
Fixed issue #476
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondap committed Aug 9, 2021
1 parent 95a861e commit eb75c3f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,17 @@ class Util {
return canWrite;
}

/**
* Returns true if dirpath is a directory.
*
* @path {string} dirpath - The path to check
*
* @returns {boolean}
*/
static isDirectory(dirpath) {
return fs.existsSync(dirpath) && fs.lstatSync(dirpath).isDirectory()
}

/**
* Returns true if dirpath is a non-empty directory.
*
Expand Down
6 changes: 6 additions & 0 deletions core/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ test('Util.canWrite()', () => {
expect(Util.canWrite(path.join(testDir, 'does-not-exist.txt'))).toBe(false);
});

test('Util.isDirectory()', () => {
expect(Util.isDirectory(__dirname)).toBe(true)
expect(Util.isDirectory(__dirname + 'zzzz8080')).toBe(false)
expect(Util.isDirectory('')).toBe(false)
});

test('Util.isNonEmptyDirectory()', () => {
expect(Util.isNonEmptyDirectory(__dirname)).toBe(true)
expect(Util.isNonEmptyDirectory(__dirname + 'zzzz8080')).toBe(false)
Expand Down
2 changes: 1 addition & 1 deletion ui/controllers/job_files_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class JobFilesController extends BaseController {
findContainingItem(filepath) {
if (Array.isArray(this.job.packageOp.sourceFiles)) {
for (let item of this.job.packageOp.sourceFiles) {
if (filepath.startsWith(item)) {
if (item === filepath || (filepath.startsWith(item) && Util.isDirectory(item))) {
return item;
}
}
Expand Down
16 changes: 16 additions & 0 deletions ui/controllers/job_files_controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,19 @@ test('deleting a file removes it from the UI and job', done => {
done();
}, timeout);
});

// https://github.com/APTrust/dart/issues/476
test('findContainingItem', () => {
let job = new Job()
job.packageOp = new PackageOperation('test', 'testy/test.tar')
job.packageOp.sourceFiles = [
__dirname,
"D:/Baby Jan",
]
let controller = new JobFilesController(new URLSearchParams())
controller.job = job

expect(controller.findContainingItem(path.join(__dirname, "photos", "image1"))).not.toBeNull()
expect(controller.findContainingItem("D:/Baby Jan")).not.toBeNull()
expect(controller.findContainingItem("D:/Baby Jan and Grandpa")).toBeNull()
});

0 comments on commit eb75c3f

Please sign in to comment.