Skip to content

Commit

Permalink
Add mkdir (#45)
Browse files Browse the repository at this point in the history
* Add makeDirectory()

Signed-off-by: Qi Liang <[email protected]>

* Bump up version to 1.0.6

Signed-off-by: Qi Liang <[email protected]>

* Add makeDirectory()

Signed-off-by: Qi Liang <[email protected]>

* Fix typo in deleteJob()

Signed-off-by: Qi Liang <[email protected]>
  • Loading branch information
std4lqi authored Jan 6, 2020
1 parent 522e337 commit 6d5f245
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This accessor leverages z/OS FTP server to interact with z/OS, it requires `JESI
* [Connection](#connection)
* [MVS dataset or USS files](#mvs-dataset-or-uss-files)
* [Allocate](#allocate)
* [Make directory](#make-directory)
* [List](#list)
* [Upload](#upload-mvs-dataset-or-uss-file)
* [Read](#read-mvs-dataset-or-uss-file)
Expand Down Expand Up @@ -146,6 +147,30 @@ connection.allocateDataset('ABC.PDS', {'LRECL': 80, 'RECFM': 'FB', 'BLKSIZE': 32
});
```

#### Make directory

`makeDirectory(directoryName)` - Make USS directory with the given directory name.

##### Parameter

* datasetName - _string_ - Dataset name to allocate.

##### Return

A promise that resolves on success, rejects on error.

##### Example

```js
connection.makeDirectory('/u/user/my_directory'})
.then(function() {
console.log('Success');
})
.catch(function(err) {
// handle error
});
```

#### List

`listDataset(dsnOrDir)` - List MVS datasets or USS files
Expand Down
35 changes: 32 additions & 3 deletions lib/zosAccessor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************/
/* */
/* Copyright (c) 2017,2018 IBM Corp. */
/* Copyright (c) 2017,2020 IBM Corp. */
/* All rights reserved. This program and the accompanying materials */
/* are made available under the terms of the Eclipse Public License v1.0 */
/* which accompanies this distribution, and is available at */
Expand Down Expand Up @@ -93,6 +93,24 @@ function allocateParamsToString(allocateParams) {
return params.join(' ');
}

/**
* Makes USS directory with the given directory name.
*
* @param {string} directoryName - Directory name
*/
ZosAccessor.prototype.makeDirectory = function(directoryName) {
var ftpClient = this.client;
var deferred = Q.defer();
ftpClient.mkdir(directoryName, function (err) {
if (err) {
deferred.reject(err);
} else {
deferred.resolve();
}
});
return deferred.promise;
}

/**
* Allocate sequential or partition (with the DCB attribut "DSORG=PO") dataset.
*
Expand Down Expand Up @@ -285,7 +303,18 @@ ZosAccessor.prototype.parseUSSDirList = function (dirList) {
for(var i=0; i<headers.length; ++i) {
entry[headers[i]] = fields[i];
}
entry['lastModified'] = new Date(fields[7], monthText.indexOf(fields[5]), fields[6]);
if (entry['permissions'] && entry['permissions'].length > 0 && entry['permissions'][0]) {
// drwx------
entry['isDirectory'] = entry['permissions'][0] === 'd';
}
if (fields[7].indexOf(':') === -1) {
// May 8 2017
entry['lastModified'] = new Date(fields[7], monthText.indexOf(fields[5]), fields[6]);
} else {
// Oct 2 09:48
var now = new Date();
entry['lastModified'] = new Date(now.getFullYear(), monthText.indexOf(fields[5]), fields[6]);
}
entry['name'] = fields.slice(8).join(' ');
entries.push(entry);
});
Expand Down Expand Up @@ -953,7 +982,7 @@ ZosAccessor.prototype.deleteJob = function (jobIdOrOption) {
var option = {};
if (typeof jobIdOrOption === 'string') {
option = { jobId: jobIdOrOption, owner: this.username };
} else if (typeof jobNameOrOption === 'object') {
} else if (typeof jobIdOrOption === 'object') {
option.jobId = option.jobId;
option.owner = option.owner || this.username;
} else {
Expand Down

0 comments on commit 6d5f245

Please sign in to comment.