Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async saveFile(
file: AbapNode,
content: Uint8Array,
uri: Uri
): Promise {
if (file.isFolder) throw FileSystemError.FileIsADirectory()
if (!isAbapNode(file))
throw FileSystemError.NoPermissions("Can only save source code")
const obj = file.abapObject
if (!obj.structure) await file.stat(this.client)
const lm = LockManager.get()
// check file is locked. Waits if locking is in progress
if (!(await lm.getFinalStatus(uri)))
throw adtException(`Object not locked ${obj.type} ${obj.name}`)
const transport = await this.selectTransportIfNeeded(
obj,
lm.getTransport(uri)
)
if (!transport.cancelled) {
let lockId = lm.getLockId(uri)
try {
await this.runInSession(client =>
obj.setContents(client, content, lockId, transport.transport)
)
} catch (e) {
if (isExpired(e) || e.type === LOCKEXPIRED) {
if (await reconnectExpired(uri)) {
lockId = lm.getLockId(uri)
obj.setContents(client, content, lockId, transport.transport)
)
} catch (e) {
if (isExpired(e) || e.type === LOCKEXPIRED) {
if (await reconnectExpired(uri)) {
lockId = lm.getLockId(uri)
await this.runInSession(client =>
obj.setContents(client, content, lockId, transport.transport)
)
} else throw e
} else throw e
}
await file.stat(this.client)
await lm.unlock(uri)
} else throw adtException("Object can't be saved without a transport")
}