Skip to content

Keep NANSEN user data outside MATLAB's preference directory - #126

Open
ehennestad wants to merge 20 commits into
devfrom
claude/project-catalog-save-path-2f51f0
Open

ehennestad wants to merge 20 commits into
devfrom
claude/project-catalog-save-path-2f51f0

Conversation

@ehennestad

@ehennestad ehennestad commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

MATLAB's preference directory belongs to a single MATLAB release. A developer moving between releases gets a separate project catalog, separate settings and separate session-method option presets in each one. An upgrade only carries them forward because MATLAB copies the previous release's directory once; moving back and forth diverges.

Change

A UserDataDirectory preference names the directory holding this user's NANSEN data. It defaults to <userpath>/Nansen/profiles/<profile>, which does not belong to a MATLAB release, and can be set to any absolute path that is not inside the current directory, does not contain it, and has no projects, settings, custom_options or local entry of its own.

userSession = nansen.internal.user.NansenUserSession.instance();
userSession.setUserDataDirectory("/Users/me/Dropbox/Nansen")
userSession.setUserDataDirectory("")   % back to the default under userpath

A session requires a userpath, because the default directory is under it. With an empty userpath(), NansenUserSession stops with the error NANSEN:UserSession:EmptyUserpath before it creates the profile's preference directory or moves any data. The default add-on folder, DefaultProjectPath and the backup paths are also under the userpath.

The preference is saved in one release's preference directory, so setUserDataDirectory also writes a directory other than the default to user_data_redirect.txt in the default directory, which every release reads. A release without its own UserDataDirectory preference uses the directory that file names, if it is an absolute path to an existing folder. setUserDataDirectory("") removes the file.

The Manage Projects tab shows the current location and offers a Change Location... button that does the same through a folder dialog, which opens at the parent of the current directory.

The directory is owned by NansenUserSession, not ProjectManager, because it holds more than the project catalog. nansen.userdatadir resolves it, mirroring nansen.prefdir; nansen.localdatadir resolves the machine specific area within it.

Profiles get their own folder under the userpath so a profile name cannot collide with the Projects, Add-Ons and Backup folders NANSEN already keeps there. Each profile resolves independently.

Layout

<prefdir>/Nansen/<profile>/              release specific
    NansenUserSession_Preferences.mat        holds UserDataDirectory
<prefdir>/javaclasspath.txt              release specific, re-applied per release

<userpath>/Nansen/profiles/<profile>/    release independent, default location
    user_data_redirect.txt                   only when the data is kept elsewhere
    user_data_layout_version.txt             layout version of this directory
    projects/project_catalog.mat
    settings/                                app behaviour, metatable column layout
    custom_options/                          session method option presets
    local/<machineId>/                   machine specific
        task_list.mat
        watch_folder_catalog.mat
        projects/<Project>/                  datalocation_local_rootpath_settings.json

What is shared and what is not

settings/ and custom_options/ hold plain user preferences — app behaviour, metatable column layout, and the option presets for session methods. None name a path or any other state of one machine.

The task list and the watch folder catalog are not like that: one names queued work, the other names paths, both belonging to the machine they were made on. They resolved under settings/. They now resolve under local/<machineId>, and every startup moves them there from settings/ if they are found there. A file that the machine folder already holds is not overwritten.

<machineId> is the MD5 hash of the hardware UUID (IOPlatformUUID from ioreg) on macOS, which does not change with the Wi-Fi network, and utility.system.getComputerName(true) on other platforms.

The add-on manifest needed nothing. It is already written to <userpath>/Nansen/Add-Ons/installed_addons.json, which does not belong to a release, and ensureAddonDependenciesOnPath re-adds add-ons to the search path each session. The copies in the preference directory are read-only leftovers of that earlier migration.

Migration — please read

Existing data is moved out of the preference directory on the next startup, per profile, as each profile's session is opened. When this release's catalog is the one moved, its entries for project folders inside the preference directory are repointed to the user data directory.

The session moves a named list of folders — projects, settings, custom_options, local — never the directory itself, so the preference file that names the location stays put. Every entry of every folder is checked for a name collision at the target before anything moves. If a move fails, exactly the entries that were moved go back, so the data is never split across two directories; the session then uses the preference directory for that run, leaves the preference unset, and tries again at the next startup.

If the user data directory already holds one of these folders with content, because another release or a machine sharing the directory migrated first, that data is used. This release's copy of the folder is renamed to <name>.unmigrated in the preference directory instead of being merged into it, and an empty copy is removed. One warning names the renamed folders and says how to add their projects to the catalog in use. The preference directory is then left without user data folders, so the migration does not run again.

A pull takes effect in a running session at once, because MATLAB applies changed class files to objects that already exist. The session then looks for its data in the user data directory before the startup that moves the data has run. The session warns once, with NANSEN:UserSession:UpdatedWhileRunning, to run nansen.restart. Until the restart, settings and option presets can look missing, and looking up a project's local folder fails. The rule above applies to a directory that a session has set up, which is one holding user_data_layout_version.txt or a project catalog. Anything in a directory that has neither was left by such a running session: each folder there is renamed to <name>.leftover, the folder from the preference directory takes its place, and a warning names the renamed folders.

If the redirect file names a folder that does not exist, for example on a drive that is not connected, the session warns, uses the default directory for that run, and moves nothing out of the preference directory.

setUserDataDirectory moves the same folders with the same all-or-nothing rule. It refuses a directory that contains any of them, so the data is never merged into a folder of the user's own, and other files in either directory stay where they are, except user_data_layout_version.txt, which follows the data.

Also in here

NansenUserSession.listUserNames also lists the folders in <userpath>/Nansen/profiles. The prompt that nansen shows for an unknown profile name, and its refusal of a name that differs from an existing profile only by capitalisation, then also see a profile whose preference directory belongs to another MATLAB release.

autoUpdateProjectPath defaulted new project folders to a projects folder inside the preference directory rather than to DefaultProjectPath, so project data could be created under the preference directory.

nansen.localpath no longer caches entries resolving under the user data directory, since that directory can move while MATLAB is running.

Path predicates are nansen.util.path.isSamePath / isSubPath / isAbsolutePath / stripTrailingSeparator. isSamePath and isSubPath ignore case on Windows and macOS, and a drive root such as Z:\ keeps its separator. nansen.internal.system.moveFolderContents returns the entries it moved and can move a named subset of entries back. The move, the startup migration, the check of a chosen directory, the redirect file and the move of the machine local files are nansen.internal.user.moveUserDataFolders, migrateUserDataFolders, validateUserDataTarget, UserDataRedirect and moveMachineLocalSettings, which UserDataFoldersTest tests on temporary folders without a user session. nansen.internal.user.UserDataLayout holds the layout version, which a later migration reads to know where to start.

Earlier commits in this branch

ProjectManager.reset looped over numel(obj.ProjectCache). ProjectCache is a containers.Map and numel of a Map is always 1, so it deleted only the first cached project and threw on an empty cache.

setProjectTablePosition read the InnerPosition of the second tab while the table it positions is on the third.

Known limitations

The catalog stores absolute project paths, and LocalRootPathManager remaps data root paths per machine with utility.system.getComputerName, a different key from <machineId> on macOS. Sharing a directory between machines needs those two mechanisms converged and the catalog's project paths routed through them. That is not in this change, and setUserDataDirectory refuses a directory that already holds another setup's data, so a second machine cannot adopt a shared one.

A release with its own UserDataDirectory preference does not read the redirect file. If another release moves the data again, that preference still names the old directory.

setUserDataDirectory deselects the current project during the move. With the App open, the App's CurrentProjectSet listener closes the task list, which stops a running task without the prompt that App.changeProject shows. Changing project from the Manage Projects dialog does the same on dev.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

769 tests  +80   768 ✅ +79   1m 57s ⏱️ +19s
 58 suites + 2     1 💤 + 1 
  1 files   ± 0     0 ❌ ± 0 

Results for commit 44abca3. ± Comparison against base commit 06e41cb.

♻️ This comment has been updated with latest results.

@ehennestad ehennestad changed the title Make the project catalog location configurable Keep NANSEN user data outside MATLAB's preference directory Sep 10, 2026
@ehennestad

Copy link
Copy Markdown
Collaborator Author

Review

Verdict: needs rework. The startup migration and setUserDataDirectory can put a user's data in the wrong folder, and the preference that names the location belongs to one MATLAB release. Nothing is deleted outright: every move is a movefile, and every rmdir is non-recursive on an emptied folder. The defects below were reproduced by running a verbatim copy of moveUserDataFolders with this PR's moveFolderContents on scratch folders.

Several of the fixes need a design decision first, so no code was changed on this branch. a99005d..dcb6c3f only merges dev (the PR conflicted on .github/badges/tests.svg), so CI runs against current dev.

Findings, most severe first:

  1. [major] NansenUserSession.m ~428-434, rollback moves too much: the rollback calls moveFolderContents(target, source), which moves every entry in the target folder, not only the entries this call moved. It also visits folders that were skipped because their source was missing, since numMoved only records the highest index reached. Failure: release B's prefdir has an empty projects/ folder (dev's getCatalogPath creates it at every session start) and a settings file that release A already migrated. The settings move fails with TargetExists, and the rollback moves A's project_catalog.mat into B's prefdir. Release A then loads an empty catalog. Fix: have moveFolderContents return the entries it moved and undo exactly those, and check all four folders for name collisions before moving any.
  2. [major] ~332-355, 426 and ProjectManagerUI.m ~890, target inside the current directory: such a target is accepted, and uigetdir(currentDirectory) opens inside that directory, next to projects, settings, custom_options and local. Choosing <current>/local moves everything into <current>/local/local/. The following rmdir fails, and nothing is undone because numMoved = i comes after the rmdir. The error says the data "was left in place", and the next session finds no catalog. Fix: refuse a target where isSubPath(newDirectory, oldDirectory) is true, set numMoved before the rmdir, and open the dialog at fileparts(currentDirectory).
  3. [major] ~357-368, target with folders of its own: assertNoCatalogAt only checks for projects/project_catalog.mat. A target that already has its own projects, settings or local folder, a Dropbox root for example, is merged into, and a later move carries the user's own files away (Dropbox/projects/MyThesis/chapter1.docx ended up in default/projects/MyThesis/ after setUserDataDirectory("")). Two profiles can also end up sharing one directory while the first has no catalog file yet. Fix (decision): refuse a target that contains any of USER_DATA_FOLDER_NAMES, or always put the data in a <chosen>/Nansen subfolder.
  4. [major] ~517-533, a second release or machine never migrates: a release that has its own catalog collides with the migrated project_catalog.mat, so it keeps using its prefdir and warns at every startup that the move "is attempted again", with a cause text ("Select a directory that does not contain…") that does not apply. In that state TaskList and WatchFolderCatalog resolve to <prefdir>/…/local/<id>/ while the files stay in settings/, because moveMachineLocalSettings runs only after a successful move. This is the user described in the Problem section. Fix (decision): when the target already holds a catalog, use the target, rename the prefdir copy (for example projects.unmigrated), and tell the user once how to import its projects.
  5. [major] ~248-251 and 664-670, release-specific location: UserDataDirectory is read from <prefdir>/Nansen/<profile>, which belongs to one release. A location chosen in one release is unknown to the other installed releases. They resolve the default, migrate their own diverged copy into it, and print that the data was moved. Fix (decision): store the location where every release reads it, for example a redirect file in the default directory that the resolver follows when the preference is unset.
  6. [major] getMachineIdentifier.m via utility.system.getComputerName, machine id changes with the network on macOS: the identifier hashes the address ifconfig en0 reports. On a Mac with private Wi-Fi addressing that is a locally administered address that macOS assigns per network and can rotate. local/<id> then changes with the network, and the project task lists, local root path files and the global task list are no longer found; on dev these sit at fixed paths. Fix: use IOPlatformUUID from ioreg -rd1 -c IOPlatformExpertDevice.
  7. [minor] ~169-175: changeProject('') fires CurrentProjectSet. With the App's Manage Projects dialog open, the listener runs onProjectChanged → closeTaskList → stopRunningTask, so a running task is cancelled without the prompt that App.changeProject shows. Fix: refuse, or ask, while a task is running.
  8. [minor] ~687-690: if userpath becomes empty after a migration, the default falls back to the prefdir, which the migration emptied, so the catalog appears empty, while the warning says the data is kept there. Fix: name the last location used, or reword the warning.
  9. [minor] stripTrailingSeparator.m:18: on Windows Z:\ becomes Z:, which isAbsolutePath rejects as relative, so a drive root such as a mapped share cannot be chosen. Fix: keep the separator after a drive letter.
  10. [nit] tools/internal/clear_tutorial_data.m deletes only the tutorial profile's prefdir, while its catalog now lives under <userpath>/Nansen/profiles/tutorial. isSamePath.m:5-6 says case is ignored "on Windows only, matching how the platform resolves paths", but default macOS volumes are case-insensitive too.

Unverified:

  • With OneDrive Known Folder Move or iCloud Desktop & Documents, userpath is synced, so the default location would share project_catalog.mat between machines. The catalog holds absolute paths and is saved as a whole file, and the PR's known limitation says sharing is not supported.
  • Under -nojvm, getComputerName(true) errors, so migrateLocalProjectFolders would throw at startup when the catalog is not empty.
  • A custom directory that is missing at startup (unmounted drive) loads an empty catalog, and nansen.localpath recreates the folders there.

Description vs code: three claims do not hold. "Puts back the ones moved before it, so the data is never split" (findings 1-2). "Anything else a user keeps in a chosen directory is left alone" (finding 3). "Tries again at the next startup" retries a move that cannot succeed (finding 4). The UI offers a shared folder "to carry this setup between machines", but assertNoCatalogAt refuses a directory that already holds the shared catalog, so a second machine cannot adopt it.

Tests: UserDataDirectoryTest covers the normal setUserDataDirectory cases, the refusal of a directory with a catalog, and input validation. Nothing tests the migration, the rollback, moveFolderContents, migrateLocalProjectFolders, moveMachineLocalSettings, repointProjectPaths or the path helpers, which is the code that runs unattended at every user's next startup. Those can be tested on temporary folders without a user session.

Out of scope (exists on dev): getComputerName already makes LocalRootPathManager's machine key depend on the network on macOS. nansen.config.abstract.Preferences caches its instance under the abstract class name, so all subclasses share one slot. DefaultProjectPath returns a relative path when userpath is empty.

Merge notes: this is the second on-disk layout change next to #119–#121. #127 also edits NansenUserSession.m: a textual merge puts this PR's public static methods getUserDataDirectory and getDefaultUserDataDirectory inside #127's methods (Static, Access = private) block, so they must be moved back to the public block when rebasing. #127's listUserNames reads prefdir/Nansen, while this PR moves profiles to userpath/Nansen/profiles, so after this PR the profile question would call an existing user unknown.

🤖 Generated with Claude Code

@ehennestad

Copy link
Copy Markdown
Collaborator Author

Review fixes

Nine of the ten findings from the review are fixed on the branch (head a884c0e). The description is rewritten to match: the three claims the review disputed now hold, and the sentence about carrying the setup between machines is removed.

  1. 02ced47: moveFolderContents returns the entries it moved and can move a named subset of entries. The new nansen.internal.user.moveUserDataFolders checks every entry of every folder for a name collision before anything moves, marks a folder as moved before its rmdir, and on failure moves back exactly the entries it moved.
  2. 02ced47: the new validateUserDataTarget refuses a target inside the current directory or containing it (NANSEN:UserSession:NestedUserDataDirectory). The folder dialog opens at the parent of the current directory.
  3. 02ced47: a target that already holds a projects, settings, custom_options or local entry is refused (UserDataDirectoryInUse); the error says to choose an empty folder or a new subfolder.
  4. 3d10cd7, 7b90a1d: when the user data directory already holds a folder with content, the startup migration uses it and renames this release's copy to <name>.unmigrated (or _2, _3, …) in the preference directory. An empty copy is removed; no file is deleted. One warning (UserDataSetAside) names the renamed folders and says how to add their projects to the catalog in use. Catalog paths are repointed only when this release's catalog was the one moved. moveMachineLocalSettings runs at every startup in the directory the session uses, never overwrites a file, and reports a failure as a warning.
  5. 491b666: setUserDataDirectory writes a location other than the default to user_data_redirect.txt in the default directory, and setUserDataDirectory("") removes the file. A release without its own UserDataDirectory preference follows the file when it names an existing folder by an absolute path; the session reads it once at startup. If the folder is missing, the session warns (UserDataRedirectUnavailable), uses the default directory for that run, and moves nothing out of the preference directory. Without a userpath no file is written.
  6. 1a3431a: on macOS the machine identifier is the MD5 hash of IOPlatformUUID from /usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice, in the same 32-character form, with getComputerName(true) as the fallback. Other platforms are unchanged.
  7. 5446262: a hidden preference, LastUserDataDirectory, records the last directory used outside the preference directory, and the empty-userpath warning names it.
  8. 960f8af: Z:\ keeps its separator. isSamePath and isSubPath ignore case on macOS as well as Windows, and isSubPath works with a root as the parent.
  9. 98cafb6, 960f8af: clear_tutorial_data also removes the tutorial profile's user data directory, and the help of isSamePath names both platforms.

Tests: the new UserDataFoldersTest (33 tests on temporary folders, no user session) covers moveFolderContents, the move and its rollback, the target checks, the migration's renaming and its undo, the move of the machine local files, the redirect file and the machine identifier. PathUtilTest has 13 new tests. UserDataDirectoryTest adds the two refusals and a redirect followed by a release without a preference of its own.

Not fixed:

  • 7, a running task cancelled without a prompt. The running state is nansen.TaskProcessor.Status, which the App keeps in its private BatchProcessor. The session has no reference to the App (NansenUserSession.setDataManagerApp is never called), and neither has ProjectManager. A check needs a public method on nansen.App, the App registering itself with the session, and the session depending on the App class; that is an API decision. The description lists it under Known limitations.
  • The three "Unverified" items of the review are unchanged.

Choices made in the fixes, for review:

  • A folder is set aside as .unmigrated whenever the target holds a non-empty folder of the same name, not only when it holds a catalog.
  • A release with its own UserDataDirectory preference does not read the redirect file. If another release moves the data later, that preference still names the old directory.
  • On macOS, local/<machineId> and the key of LocalRootPathManager (utility.system.getComputerName) are now different values.
  • ProjectManager.relocate and the migration's repointing rewrite every catalog path inside the old directory, while only the four named folders move. A project folder kept directly in a chosen directory, outside projects/, would get a wrong path.

The merge notes on #127 in the review still apply.

🤖 Generated with Claude Code

@ehennestad

Copy link
Copy Markdown
Collaborator Author

Merge of dev after #127

#127 is in dev, so the branch now merges dev (6013cd9), following the merge notes in the #127 review.

  • .github/badges/tests.svg: dev's version.
  • Preferences.m: dev's fromStruct from fix(prefs): skip saved preferences the class does not declare #172. It skips saved preferences the class does not declare, as this branch's version did, so this PR no longer changes the file. The description no longer lists that change.
  • NansenUserSession.m merges without a conflict, but git puts getUserDataDirectory and getDefaultUserDataDirectory after feat(user): confirm creation of unknown user profiles #127's confirmNewUserProfile, inside its methods (Static, Access = private) block. They are back in the public static block, unchanged. nansen.userdatadir, clear_tutorial_data, ProjectFixture and UserDataDirectoryTest call them from outside the class. Apart from that, the merged file is this branch's version plus exactly feat(user): confirm creation of unknown user profiles #127's change.
  • Project.m and ProjectFixture.m merge cleanly: the two sides change different methods.

The other merge note is settled in 0a2ed8a: #127's listUserNames listed only the folders in prefdir/Nansen, which belongs to one MATLAB release. A profile created in another release has only its user data directory, <userpath>/Nansen/profiles/<name>, in this one. The prompt then called that profile unknown, and the capitalisation check could not see it: nansen("John") could create a profile next to an existing john from another release, and on macOS and Windows the two used the same user data directory. listUserNames now also lists <userpath>/Nansen/profiles; the path of that folder moves into a private getDefaultUserDataRoot, which getDefaultUserDataDirectory also uses. Two new tests in NansenUserSessionTest cover the listing and the capitalisation refusal for such a profile.

A session for a new profile creates only its preference directory, so the throwaway profiles of NansenUserSessionTest and PreferencesTest leave nothing under the userpath.

🤖 Generated with Claude Code

@ehennestad
ehennestad force-pushed the claude/project-catalog-save-path-2f51f0 branch from d3b521c to d7ad22e Compare November 8, 2026 15:58
@ehennestad ehennestad self-assigned this Nov 8, 2026
ehennestad and others added 20 commits November 9, 2026 09:49
reset looped over numel(obj.ProjectCache), but ProjectCache is a
containers.Map and numel of a Map is the number of Map objects, which is
always 1. The loop therefore deleted only the first cached project, and
on an empty cache it indexed keys{1} into an empty cell array and threw.

Loop over the key list instead, whose numel is the number of entries.

The method has no callers yet, so nothing was hitting this. It is the
first thing that a caller clearing the cache would have run into.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The project catalog lived in a "projects" folder under MATLAB's
preference directory. That directory belongs to a single MATLAB release,
so upgrading MATLAB left the new release without any projects.

Add a ProjectCatalogDirectory user preference naming the directory that
holds the catalog. An empty value keeps the previous default, so nothing
changes for an installation that does not set it. ProjectManager gains
setCatalogDirectory, which moves the catalog and the project
configurations stored next to it, then remembers the location. Passing
an empty value moves everything back to the preference directory.

The move refuses a destination that already holds a project catalog, so
an existing catalog is never overwritten, and resolves every entry it
will write before moving anything. A move that fails partway puts back
what it already moved, so the catalog is never split across two
directories. A legacy installation can keep project folders inside the
catalog directory; those entries are repointed at their new path.

Machine specific project configurations, such as local data root paths
and task lists, used to sit directly in the catalog directory, one
folder per project. They now live under local/<machineId>, so that a
catalog directory placed on a shared or synchronized folder does not
have two machines overwriting each other's configurations. The machine
key is the identifier the data location model already uses as its
SourceID, so there is one notion of machine identity rather than two.
Existing installations are migrated to that layout on the next startup;
a folder that is a project's own path is left alone, because that is
project data rather than configuration.

The preference is read from file rather than from the user session,
because the session builds its project manager before the session
singleton is reachable.

Note that the catalog stores absolute project paths. Sharing a catalog
between machines therefore still requires the project folders to be
reachable at the same paths on both.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The Manage Projects tab now shows where the project catalog is saved and
offers a button to move it. The button explains why the location matters,
opens a folder dialog, and reports what happened, so the location can be
changed without calling setCatalogDirectory from the command line.

The table and the new controls share the tab, so positioning them is one
step: the table reserves a strip along the bottom, and the controls are
placed in it. The button keeps a fixed width and the label takes the
remainder, with the full path in its tooltip because a long preference
directory path does not fit in a small window.

setProjectTablePosition read the InnerPosition of the second tab while
the table it positions is on the third. Sibling tabs report the same
InnerPosition, so this went unnoticed. Look the tab up by title instead,
so the table and the new controls share one reference.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…er UI

The label and the dialog spelled out the catalog directory as a path. In
the default location that path is a long preference directory that says
little, and it is the location the feature exists to move away from.

Report it as "MATLAB's preference folder" instead, and keep the path in
the label tooltip and in the dialog body. The dialog explains in that
case that the folder belongs to a single MATLAB release, which is the
reason to move the catalog. A catalog that has been moved is still shown
by its path, since that is what identifies it.

Add isCatalogDirectoryDefault to answer the question, so that the UI does
not derive the default location itself, and give ProjectManager one
private helper for that location rather than building it in three places.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
MATLAB's preference directory belongs to a single release. A developer
who moves between releases gets a separate project catalog, separate
project configurations and a separate add-on manifest in each one, and
an upgrade only carries them forward by copying the previous release's
directory once.

Replace the ProjectCatalogDirectory preference, which named a folder
inside that directory, with UserDataDirectory, which names the directory
itself. It defaults to <userpath>/Nansen/profiles/<profile>, which does
not belong to a release, and can be set to any absolute path, including
a shared or synchronized folder. The profiles are kept in their own
folder so that a profile name can not collide with the Projects, Add-Ons
and Backup folders NANSEN already keeps under the userpath.

The directory is owned by NansenUserSession rather than ProjectManager,
because it holds more than the project catalog. ProjectManager derives
its catalog directory from it and is repointed by the session when it
moves. Existing data is moved out of the preference directory on the
next startup, and project folders kept inside it are repointed in the
catalog. A move that fails leaves the data where it is and records the
preference to match, so a failed migration cannot start NANSEN with an
empty project catalog.

Preference files written before this can name preferences that no longer
exist, so loading now skips unknown names rather than erroring on them.

Move the path predicates and the folder move into nansen.util.path and
nansen.internal.system, where the session and the project manager can
both reach them and where they can be tested directly.

Two locations that were still release specific:
autoUpdateProjectPath defaulted new project folders to a "projects"
folder in the preference directory rather than to DefaultProjectPath.

The settings and custom_options folders, and the add-on manifest, still
live in the preference directory. They move in a later change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The settings and custom_options folders held user configuration in the
preference directory, so they were left behind on a MATLAB upgrade like
the project catalog was. Move them into the user data directory, and
migrate existing ones on the next startup.

Both hold plain user preferences: app behaviour, metatable column
layout, and the option presets for session methods. None of them name a
path or any other state of one machine, so they are shared when the user
data directory is.

Two files are not like that. The task list names queued work and the
watch folder catalog names paths, both belonging to the machine they
were made on, and both resolved under the settings folder. Sharing that
folder would have shared them too. Resolve them under a machine specific
directory instead, and move them there during the migration.

That directory moves up out of the catalog folder to nansen.localdatadir,
since it now holds more than project configurations. The project
configurations keep their own subfolder within it. The machine identifier
moves to nansen.internal.system.getMachineIdentifier, next to the other
system helpers, since the project manager is no longer its only caller.

nansen.localpath no longer caches entries that resolve under the user
data directory, because that directory can move while MATLAB is running.
The user_data keyword named the preference directory, which is no longer
where the user's data is kept.

The add-on manifest needed nothing. It is already written to the add-on
folder under the userpath, which does not belong to a MATLAB release,
and the copies in the preference directory are read only leftovers of
that earlier migration.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review of the branch found two defects that would fail its own tests, a
guarantee the migration did not keep, and a test fixture that leaked.

setUserDataDirectory failed on every fresh target. The check for an
existing catalog called getCatalogPath, which created the catalog folder
as a side effect, so the move that followed found its own target already
present and refused. getCatalogPath no longer creates anything; the
folder is created where it is needed, in saveCatalog.

The startup migration resolved the machine specific folder through the
session singleton, which is not registered until the constructor has
returned, so it resolved for the anonymous user and put the task list in
the wrong profile. It now derives the folder from the directory it was
given; localdatadir takes that directory as an optional argument.

The migration promised not to start NANSEN with an empty catalog after a
failed move, but only rolled back within one folder. A failure on the
second folder left the first already moved. The session now moves a
named list of folders as a unit and puts back the completed ones on
failure. Moving named folders rather than the directory also keeps the
preference file in place when the source is the preference directory,
and leaves alone anything else a user keeps in a directory they chose.

A failed migration no longer pins the preference to the preference
directory, which was permanent despite the message saying "for now".
The session uses the old location for this run only and the move is
attempted again at the next startup.

ProjectFixture removed the test profile's preference directory but not
its user data directory, so every run left a folder under the userpath.

Resolution no longer reads the preference file on every path lookup.
An active session answers from memory; the file is read only when there
is no session. The empty userpath warning moves out of the resolver,
which runs on every lookup, into the constructor, which runs once.

ProjectManager keeps the directory it was built for and derives its
locations from it, rather than re-resolving through the session. The
repointing of project paths that moved with a directory is one function
shared by the manager and the migration.

The Manage Projects controls are named for the user data location they
manage, the label shows the path since the default is short now, and
stale references to configurations living in the catalog folder are
corrected.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
stripTrailingSeparator turned Z:\ into Z:, which names the current
folder on drive Z and which isAbsolutePath rejects, so a drive root
could not be chosen as the user data directory. A separator after a
drive letter is now kept.

isSamePath compared case-sensitively on macOS, whose default APFS
volumes do not distinguish case. It now ignores case on macOS as on
Windows, and isSubPath follows the same rule.

isSubPath appended a separator to a root that already ends with one, so
no path was inside / or Z:\, and it reported a path with a trailing
separator as inside the folder that path names. Both are fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rollback after a failed move called moveFolderContents with the
directories swapped, which moves every entry of the target folder, not
only the entries the move put there. It also visited folders that were
skipped, because numMoved only recorded the highest index reached, and
numMoved was set after the rmdir of the emptied source folder, so a
failed rmdir was not undone. A release whose preference directory held
an empty projects folder and a settings file that another release had
already moved could carry that release's project catalog back into its
own preference directory.

moveFolderContents now returns the names of the entries it moved, and
moves only named entries when given EntryNames. The folder move is a
function, nansen.internal.user.moveUserDataFolders, that checks every
entry of every folder for a collision before anything moves, records
the moved folders in a logical array before removing the emptied source
folder, and moves back exactly the entries it moved.

setUserDataDirectory now refuses a directory that is inside the current
one or contains it, and a directory that already contains a projects,
settings, custom_options or local entry, through
nansen.internal.user.validateUserDataTarget. The first stops a folder
from being moved into itself, as when <current>/local is chosen. The
second stops the data from being merged into a folder of the user's
own, and two profiles from sharing a directory. The folder dialog opens
at the parent of the current directory, and no longer suggests that a
synchronized folder carries the setup between machines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A release whose preference directory still held its own catalog
collided with the catalog that another release, or another machine
sharing the directory, had already moved to the user data directory.
The move failed, the session fell back to the preference directory,
and the move was attempted, and failed, at every startup. In that state
TaskList and WatchFolderCatalog resolved to <prefdir>/local/<id> while
the files stayed in settings, because the machine local files were only
moved after a successful migration.

The startup migration now goes through
nansen.internal.user.migrateUserDataFolders. A folder that the user
data directory already holds with content is used as it is, and this
release's copy is renamed to <name>.unmigrated in the preference
directory instead of merged. An empty copy is removed. The other folders
move as before, and a failure undoes the renames along with the moves.
The preference directory is left without user data folders, so the
migration does not run again. One warning names the renamed folders and
says how to add their projects to the catalog in use.

moveMachineLocalSettings is a function and runs at every startup in the
directory the session uses, so the task list and the watch folder
catalog are where nansen.localpath looks for them, also when the
preference directory is used. It no longer overwrites a file that the
machine folder already holds. Catalog paths are repointed only when this
release's catalog was the one moved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UserDataDirectory preference is read from <prefdir>/Nansen/<profile>,
which belongs to one MATLAB release. A location chosen in one release
was unknown to the others: they resolved the default directory, moved
their own copy of the data into it, and reported that the data was
moved.

When setUserDataDirectory chooses a directory other than the default,
it now also writes that directory to user_data_redirect.txt in the
default directory, <userpath>/Nansen/profiles/<profile>, which every
release reads. A release whose own preference is unset uses the
directory that the file names, if it is an absolute path to an existing
folder. Moving the data back to the default removes the file. Without a
userpath the default directory is the preference directory, and no file
is written. nansen.internal.user.UserDataRedirect reads and writes the
file.

The session reads the redirect file once at startup. If the file names
a folder that does not exist, for example on a drive that is not
connected, the session warns, uses the default directory for that
session, and moves nothing out of the preference directory, so that the
data is not moved to a directory the next session will not use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getMachineIdentifier hashed the address that ifconfig reports for en0,
through utility.system.getComputerName. With private Wi-Fi addressing
on, that is an address macOS assigns per Wi-Fi network, so local/<id>
changed with the network, and the task list, the watch folder catalog
and the local project configurations were no longer found.

On macOS the identifier is now the MD5 hash of the IOPlatformUUID that
/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice reports, in the same
32 character form as before. If ioreg reports no UUID, and on other
platforms, the identifier is still utility.system.getComputerName(true).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a userpath the default user data directory is this release's
preference directory. After a startup migration that directory no longer
holds the data, so the catalog appeared empty, while the warning said
that NANSEN keeps its data there.

The session now records the directory it uses in a LastUserDataDirectory
preference, whenever that is not the preference directory, at startup
and after setUserDataDirectory. With an empty userpath the warning names
the preference directory as the one used and the recorded directory as
the one that holds the earlier data, and says to set the userpath again.
Without a record the warning is unchanged. The preference is hidden from
the preference display, because the session sets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clear_tutorial_data removed only the tutorial profile's preference
directory, while its catalog and configurations now live in
<userpath>/Nansen/profiles/tutorial. The script now removes that
directory as well, unless it is the preference directory, as it is when
userpath is empty. Either removal is skipped when its folder is
missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a session

The task list and the watch folder catalog are moved out of the settings
folder at every startup. An error there, for example from a settings
folder that can not be written, or from resolving the machine
identifier without a Java virtual machine, stopped the user session
from being created.

The session now reports such an error as a warning and starts.
moveMachineLocalSettings also returns before resolving the machine
folder when the settings folder holds neither file, which is the case
at most startups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a userpath the default user data directory is the preference
directory, and setUserDataDirectory writes no redirect file, so the
test can not check one. It is filtered in that case, like the test of
the default location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
listUserNames, from #127, listed the folders in prefdir/Nansen, which
belongs to one MATLAB release. A profile created in another release
has only its user data directory, <userpath>/Nansen/profiles/<name>,
in this one. The confirmation prompt then called it unknown, and the
capitalisation check could not see it: nansen("John") could create a
profile next to an existing "john" from another release, and on macOS
and Windows the two used the same user data directory.

listUserNames now also lists the default user data root. The path of
that root moves into getDefaultUserDataRoot, which
getDefaultUserDataDirectory also uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default user data directory is under MATLAB's userpath. With an
empty userpath the session fell back on the preference directory, which
belongs to one MATLAB release. A fresh MATLAB never reached the
fallback, because the add-on manager requires a userpath. Where it was
reached, setUserDataDirectory wrote no redirect file and gave no
warning.

An empty userpath now stops the session with
NANSEN:UserSession:EmptyUserpath. The check comes before the profile's
preference directory is created, so a failed start leaves no profile
behind. The fallback, its startup warning and the LastUserDataDirectory
preference are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The help text of NansenUserSession.instance placed a profile's
projects in its preference directory. They are in its user data
directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MATLAB applies a pulled change to a running session at once, so the
session looks for its data where the new code expects it before the
startup that moves the data has run. A file saved in that window made
the next startup treat the new location as data another release had
moved there, and set the real folder aside as <name>.unmigrated.

A session now stores the layout version in the user data directory. A
directory with neither that version nor a project catalog has not been
set up, so what it holds is left over from a running session: those
folders are renamed to <name>.leftover and the real data moves into
place. The version follows the data in setUserDataDirectory.

A session compares the current layout version with the one it started
with and tells the user once to run nansen.restart.

saveCatalog takes the folder from CatalogPath, because a session started
by older code has no CatalogDirectory and every save failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant