Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function hasGitNotebook(): boolean {
if (!baseEnabled()) {
return false;
}
let path = tracker.currentWidget!.context.path;
let dir = PathExt.dirname(path);
let known_git = lut_known_git[dir];
if (known_git === undefined) {
const inGitPromise = isNbInGit({path: dir});
inGitPromise.then(inGit => {
networkRetry = INITIAL_NETWORK_RETRY;
lut_known_git[dir] = inGit;
// Only update if false, since it is left enabled while waiting
if (!inGit) {
commands.notifyCommandChanged(CommandIDs.diffNotebookGit);
}
});
inGitPromise.catch((reason) => {
hasAPI = reason.status !== undefined && reason.status !== 404;
setTimeout(() => {
networkRetry *= 2;
commands.notifyCommandChanged(CommandIDs.diffNotebook);
it('should not return "." for an empty path', () => {
const path = PathExt.dirname('');
expect(path).to.equal('');
});
it('should not return "." for a path in the root directory', () => {
const path = PathExt.dirname('foo.txt');
expect(path).to.equal('');
});
});
resourceCache.forEach((value, key) => {
let enclosingFolderPath = PathExt.dirname(key);
if (path === enclosingFolderPath) {
resourceCache.delete(key);
}
});
}
return restored.then(() => model.cd(`/${PathExt.dirname(localPath)}`));
});
async (resolve, reject) => {
let enclosingFolderPath = PathExt.dirname(path);
const resource: FileResource = fileResourceFromContentsModel(
model,
fileType
);
const parentFolderResource = await getResourceForPath(
enclosingFolderPath
);
if (!isDirectory(parentFolderResource)) {
throw new Error('Google Drive: expected a folder: ' + path);
}
if (parentFolderResource.kind === 'drive#teamDrive') {
resource.teamDriveId = parentFolderResource.id;
} else if (parentFolderResource.teamDriveId) {
resource.teamDriveId = parentFolderResource.teamDriveId;
}
resource.parents = [parentFolderResource.id!];
resolveUrl(url: string): Promise {
if (this.isLocal(url)) {
const cwd = encodeURI(PathExt.dirname(this._session.path));
url = PathExt.resolve(cwd, url);
}
return Promise.resolve(url);
}
export async function uploadFile(
path: string,
model: Partial,
fileType: DocumentRegistry.IFileType,
existing: boolean = false,
fileTypeForPath:
| ((path: string) => DocumentRegistry.IFileType)
| undefined = undefined
): Promise {
if (isDummy(PathExt.dirname(path)) && !existing) {
throw makeError(
400,
`Google Drive: "${path}"` + ' is not a valid save directory'
);
}
let resourceReadyPromise: Promise;
if (existing) {
resourceReadyPromise = getResourceForPath(path);
} else {
resourceReadyPromise = new Promise(
async (resolve, reject) => {
let enclosingFolderPath = PathExt.dirname(path);
const resource: FileResource = fileResourceFromContentsModel(
model,
fileType
);
onClick: () => {
var datavoyager = (widget as VoyagerPanel).voyager_cur;
var dataSrc = (widget as VoyagerPanel).data_src;
let spec = datavoyager.getSpec(false);
let context = widget.context as Context;
let path = PathExt.dirname(context.path);
var content: any;
if (spec !== undefined) {
content = {
data: dataSrc,
mark: spec.mark,
encoding: spec.encoding,
height: spec.height,
width: spec.width,
description: spec.description,
name: spec.name,
selection: spec.selection,
title: spec.title,
transform: spec.transform
};
} else {
content = {
}).then(result => {
if (!result.value) {
return null;
}
if (!isValidFileName(result.value)) {
void showErrorMessage(
'Rename Error',
Error(
`"${result.value}" is not a valid name for a file. ` +
`Names must have nonzero length, ` +
`and cannot include "/", "\\", or ":"`
)
);
return null;
}
let basePath = PathExt.dirname(oldPath);
let newPath = PathExt.join(basePath, result.value);
return renameFile(manager, oldPath, newPath);
});
}