Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions indax.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SmbDirectoryHandle extends SmbHandle {
if (errMsg == 'The path supplied exists, but was not an entry of requested type.') {
reason.name = 'TypeMismatchError';
}
else if (errMsg.indexOf('not found') != -1) {
else if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.name = 'NotFoundError';
}
}
Expand All @@ -107,7 +107,7 @@ class SmbDirectoryHandle extends SmbHandle {
if (errMsg == 'The path supplied exists, but was not an entry of requested type.') {
reason.name = 'TypeMismatchError';
}
else if (errMsg.indexOf('not found') != -1) {
else if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.name = 'NotFoundError';
}
}
Expand Down Expand Up @@ -149,13 +149,35 @@ class SmbFileHandle extends SmbHandle {
throw Error('createSyncAccessHandle not implemented');
}
async getFile() {
return this._js.getFile();
return new Promise(async (resolve, reject) => {
await this._js.getFile()
.then((file) => resolve(file))
.catch((reason) => {
let errMsg = reason.message;
if (errMsg !== undefined) {
if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.message = `File "${this.name}" not found`;
reason.name = 'NotFoundError';
}
}
reject(reason);
});
});
}
async createWritable(options) {
return new Promise(async (resolve, reject) => {
await this._js.createWritable(options)
.then((stream) => resolve(new SmbWritableFileStream(stream)))
.catch((reason) => reject(reason));
.catch((reason) => {
let errMsg = reason.message;
if (errMsg !== undefined) {
if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.message = `File "${this.name}" not found`;
reason.name = 'NotFoundError';
}
}
reject(reason);
});
});
}
}
Expand Down
30 changes: 26 additions & 4 deletions indax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SmbDirectoryHandle extends SmbHandle implements FileSystemDirectory
if (errMsg !== undefined) {
if (errMsg == 'The path supplied exists, but was not an entry of requested type.') {
reason.name = 'TypeMismatchError';
} else if (errMsg.indexOf('not found') != -1) {
} else if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.name = 'NotFoundError';
}
}
Expand All @@ -124,7 +124,7 @@ export class SmbDirectoryHandle extends SmbHandle implements FileSystemDirectory
if (errMsg !== undefined) {
if (errMsg == 'The path supplied exists, but was not an entry of requested type.') {
reason.name = 'TypeMismatchError';
} else if (errMsg.indexOf('not found') != -1) {
} else if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.name = 'NotFoundError';
}
}
Expand Down Expand Up @@ -172,13 +172,35 @@ export class SmbFileHandle extends SmbHandle implements FileSystemFileHandle {
}

async getFile(): Promise<File> {
return this._js.getFile();
return new Promise(async (resolve, reject) => {
await this._js.getFile()
.then((file) => resolve(file))
.catch((reason) => {
let errMsg: string = reason.message;
if (errMsg !== undefined) {
if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.message = `File "${this.name}" not found`;
reason.name = 'NotFoundError';
}
}
reject(reason);
});
});
}
async createWritable(options?: SmbCreateWritableOptions): Promise<FileSystemWritableFileStream> {
return new Promise(async (resolve, reject) => {
await this._js.createWritable(options as JsSmbCreateWritableOptions)
.then((stream) => resolve(new SmbWritableFileStream(stream) as FileSystemWritableFileStream))
.catch((reason) => reject(reason));
.catch((reason) => {
let errMsg: string = reason.message;
if (errMsg !== undefined) {
if (errMsg.indexOf('not found') != -1 || errMsg.indexOf('ENOENT') != -1) {
reason.message = `File "${this.name}" not found`;
reason.name = 'NotFoundError';
}
}
reject(reason);
});
});
}
}
Expand Down
9 changes: 7 additions & 2 deletions libsmb2-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ fn check_mut_ptr<T>(ptr: *mut T) -> Result<*mut T> {
fn check_retcode(ctx: *mut smb2_context, code: i32) -> Result<()> {
if code < 0 {
unsafe {
let err_str = smb2_get_error(ctx);
let e = CStr::from_ptr(err_str).to_string_lossy().into_owned();
let err_ptr = smb2_get_error(ctx);
let err_str = CStr::from_ptr(err_ptr).to_string_lossy().into_owned();
let e = if !err_str.is_empty() {
err_str
} else {
nix::errno::Errno::from_raw(-code).to_string()
};
Err(Error::new(ErrorKind::Other, e))
}
} else {
Expand Down
Loading