packages/slave/slave.js
/**
 * Create and update symlinks for shared mods in an instance
 *
 * Creates symlinks for .zip and .dat files that are not present in the
 * instance mods directory but is present in the sharedMods directory,
 * and removes any symlinks that don't point to a file in the instance
 * mods directory.  If the instance mods directory doesn't exist it will
 * be created.
 *
 * Note that on Windows this creates hard links instead of symbolic
 * links as the latter requires elevated privileges.  This unfortunately
 * means the removal of mods from the shared mods dir can't be detected.
 *
 * @param {Instance} instance - Instance to link mods for
 * @param {string} sharedMods - Path to folder to link mods from.
 */
Create and update symlinks for shared mods in an instance
Creates symlinks for .zip and .dat files that are not present in the
instance mods directory but is present in the sharedMods directory,
and removes any symlinks that don't point to a file in the instance
mods directory.  If the instance mods directory doesn't exist it will
be created.

Note that on Windows this creates hard links instead of symbolic
links as the latter requires elevated privileges.  This unfortunately
means the removal of mods from the shared mods dir can't be detected.

@param {Instance} instance - Instance to link mods for
@param {string} sharedMods - Path to folder to link mods from.
Create and update symlinks for shared mods in an instance Creates symlinks for . zip and . dat files that are not present in the instance mods directory but is present in the sharedMods directory and removes any symlinks that don ' t point to a file in the instance mods directory . If the instance mods directory doesn ' t exist it will be created . Note that on Windows this creates hard links instead of symbolic links as the latter requires elevated privileges . This unfortunately means the removal of mods from the shared mods dir can ' t be detected . @param { Instance } instance - Instance to link mods for @param { string } sharedMods - Path to folder to link mods from .
async function symlinkMods(instance, sharedMods) {
	await fs.ensureDir(instance.path("mods"));
	for (let entry of await fs.readdir(instance.path("mods"), { withFileTypes: true })) {
		if (entry.isSymbolicLink()) {
			if (!await fs.pathExists(instance.path("mods", entry.name))) {
				instance.logger.verbose(`Removing broken symlink ${entry.name}`);
				await fs.unlink(instance.path("mods", entry.name));
			}
		}
	}
	let instanceModsEntries = new Set(await fs.readdir(instance.path("mods")));
	for (let entry of await fs.readdir(sharedMods, { withFileTypes: true })) {
		if (entry.isFile()) {
			if ([".zip", ".dat", ".json"].includes(path.extname(entry.name))) {
				if (!instanceModsEntries.has(entry.name)) {
					instance.logger.verbose(`linking ${entry.name} from ${sharedMods}`);
					let target = path.join(sharedMods, entry.name);
					let link = instance.path("mods", entry.name);
					if (process.platform !== "win32") {
						await fs.symlink(path.relative(path.dirname(link), target), link);
					} else {
						await fs.link(target, link);
					}
				}
			} else {
				instance.logger.warn(`Warning: ignoring file '${entry.name}' in sharedMods`);
			}
		} else {
			instance.logger.warn(`Warning: ignoring non-file '${entry.name}' in sharedMods`);
		}
	}
}
async function symlinkMods ( instance , sharedMods ) { await fs . ensureDir ( instance . path ( "mods" ) ) ; for ( let entry of await fs . readdir ( instance . path ( "mods" ) , { withFileTypes : true } ) ) { if ( entry . isSymbolicLink ( ) ) { if ( ! await fs . pathExists ( instance . path ( "mods" , entry . name ) ) ) { instance . logger . verbose ( ` ${ entry . name } ` ) ; await fs . unlink ( instance . path ( "mods" , entry . name ) ) ; } } } let instanceModsEntries = new Set ( await fs . readdir ( instance . path ( "mods" ) ) ) ; for ( let entry of await fs . readdir ( sharedMods , { withFileTypes : true } ) ) { if ( entry . isFile ( ) ) { if ( [ ".zip" , ".dat" , ".json" ] . includes ( path . extname ( entry . name ) ) ) { if ( ! instanceModsEntries . has ( entry . name ) ) { instance . logger . verbose ( ` ${ entry . name } ${ sharedMods } ` ) ; let target = path . join ( sharedMods , entry . name ) ; let link = instance . path ( "mods" , entry . name ) ; if ( process . platform !== "win32" ) { await fs . symlink ( path . relative ( path . dirname ( link ) , target ) , link ) ; } else { await fs . link ( target , link ) ; } } } else { instance . logger . warn ( ` ${ entry . name } ` ) ; } } else { instance . logger . warn ( ` ${ entry . name } ` ) ; } } }
Create and update symlinks for shared mods in an instance
 Creates symlinks for .zip and .dat files that are not present in the
 instance mods directory but is present in the sharedMods directory,
 and removes any symlinks that don't point to a file in the instance
 mods directory.
Create and update symlinks for shared mods in an instance Creates symlinks for . zip and . dat files that are not present in the instance mods directory but is present in the sharedMods directory and removes any symlinks that don ' t point to a file in the instance mods directory .
// Remove broken symlinks in instance mods. // Link entries that are in sharedMods but not in instance mods. /* eslint-disable max-depth */ // On Windows symlinks require elevated privileges, which is // not something we want to have.  For this reason the mods // are hard linked instead.  This has the drawback of not // being able to identify when mods are removed from the // sharedMods directory, or which mods are linked. /* eslint-enable max-depth */