index.js
function takeOwnership(filePath) {

	try {

		var stats = fs.lstatSync(filePath);

		if (stats.isDirectory()) {
			execSyncElevated('takeown /f "' + filePath + '" /r /d y');
		} else {
			execSyncElevated('takeown /f "' + filePath + '"');
		}

		return;

	} catch (error) {

		if (error.code === 'ENOENT') {
			console.warn('takeown:', filePath, 'does not exist.');
			return;
		}

		// fs.lstatSync can fail with EPERM on Windows so retry
		// after taking control of this specific path.
		if (error.code === 'EPERM') {
			execSyncElevated('takeown /f "' + filePath + '"');
			return takeOwnership(filePath);
		}
	}
}
function takeOwnership(filePath) {

	try {

		var stats = fs.lstatSync(filePath);

		if (stats.isDirectory()) {
			execSyncElevated('takeown /f "' + filePath + '" /r /d y');
		} else {
			execSyncElevated('takeown /f "' + filePath + '"');
		}

		return;

	} catch (error) {

		if (error.code === 'ENOENT') {
			console.warn('takeown:', filePath, 'does not exist.');
			return;
		}

		// fs.lstatSync can fail with EPERM on Windows so retry
		// after taking control of this specific path.
		if (error.code === 'EPERM') {
			execSyncElevated('takeown /f "' + filePath + '"');
			return takeOwnership(filePath);
		}
	}
}
function takeOwnership ( filePath ) { try { var stats = fs . lstatSync ( filePath ) ; if ( stats . isDirectory ( ) ) { execSyncElevated ( 'takeown /f "' + filePath + '" /r /d y' ) ; } else { execSyncElevated ( 'takeown /f "' + filePath + '"' ) ; } return ; } catch ( error ) { if ( error . code === 'ENOENT' ) { console . warn ( 'takeown:' , filePath , 'does not exist.' ) ; return ; } // fs.lstatSync can fail with EPERM on Windows so retry // after taking control of this specific path. if ( error . code === 'EPERM' ) { execSyncElevated ( 'takeown /f "' + filePath + '"' ) ; return takeOwnership ( filePath ) ; } } }
Calls fire and forget Windows specific command to seize control of a file or directory. Never seems to fail but we don't get any confirmation of success.
Calls fire and forget Windows specific command to seize control of a file or directory . Never seems to fail but we don t get any confirmation of success .