private void writeIndex() throws IOException {

		if (readOnly) {
			throw new IOException("Unexpected attempt to write index for read-only filesystem");
		}

		MessageDigest messageDigest = null;
		try {
			messageDigest = MessageDigest.getInstance("MD5");
		}
		catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e.toString());
		}

		File tempIndexFile = new File(root, TMP_INDEX_FILE);
		tempIndexFile.delete();
		PrintWriter indexWriter = new PrintWriter(tempIndexFile, "UTF8");
		try {
			int version = getIndexImplementationVersion();
			if (version != 0) {
				String versionLine = INDEX_VERSION_PREFIX + version;
				digest(versionLine, messageDigest);
				indexWriter.println(versionLine);
			}
			writeIndexFolder(indexWriter, rootFolder, messageDigest);
			String idLine = NEXT_FILE_INDEX_ID_PREFIX + Long.toHexString(nextFileIndexID);
			digest(idLine, messageDigest);
			indexWriter.println(idLine);
			indexWriter.println(
				MD5_PREFIX + NumericUtilities.convertBytesToString(messageDigest.digest()));
			indexWriter.flush();
			indexWriter.close();
			if (indexWriter.checkError()) {
				indexWriter = null;
				throw new IOException(
					"error occurred while writing filesystem index: " + tempIndexFile);
			}
		}
		finally {
			if (indexWriter != null) {
				indexWriter.close();
			}
		}

		File backupIndexFile = new File(root, BAK_INDEX_FILE);
		File backupJournalFile = new File(root, BAK_JOURNAL_FILE);

		if (indexFile.exists()) {
			backupIndexFile.delete();
			backupJournalFile.delete();
			if (!indexFile.renameTo(backupIndexFile)) {
				throw new IOException("failed to backup filesystem index: " + indexFile);
			}
			if (journalFile.exists() && !journalFile.renameTo(backupJournalFile)) {
				backupIndexFile.renameTo(indexFile);
				throw new IOException("failed to backup filesystem journal: " + journalFile);
			}
		}
		else {
			backupIndexFile.delete();
			backupJournalFile.delete();
			backupIndexFile = null;
			backupJournalFile = null;
		}

		if (!tempIndexFile.renameTo(indexFile)) {
			// hopefully we can restore index
			if (backupIndexFile != null) {
				backupIndexFile.renameTo(indexFile);
			}
			if (backupJournalFile != null) {
				backupJournalFile.renameTo(journalFile);
			}
			throw new IOException("failed to update filesystem index (2): " + indexFile);
		}

		journalCount = 0;
	}
Writes current folder index.
@throws IOException
Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/IndexedLocalFileSystem.java