eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.55k stars 2.46k forks source link

Failed to customize the data folder #13700

Closed fanyipin closed 2 months ago

fanyipin commented 2 months ago

Bug Description:

Prior to version 1.44, the ConfigDirUri variable could be customized via process.env.THEIA_CONFIG_DIR. This meant users could set process.env.THEIA_CONFIG_DIR within their application to specify a custom data directory. However, after the introduction of the logic in the app directory in version 1.44, process.env.THEIA_CONFIG_DIR is being re-assigned, which seems to override previous settings. I understand that there should be a priority order where:

  1. User-defined settings take precedence,
  2. Followed by application-specific settings if defined,
  3. Lastly, defaulting to the standard THEIA directory if neither is provided.

Here is the logical code for handling ConfigDirUri, which I understand should not be specified directly if process.env.THEIA_CONFIG_DIR has a value

protected async createConfigDirUri(): Promise<string> {
      const dataFolderPath = join(BackendApplicationPath, 'data');
      const userDataPath = join(dataFolderPath, 'user-data');
      const dataFolderExists = this.pathExistenceCache[dataFolderPath] ??= await pathExists(dataFolderPath);
      if (dataFolderExists) {
          const userDataExists = this.pathExistenceCache[userDataPath] ??= await pathExists(userDataPath);
          if (userDataExists) {
              process.env.THEIA_CONFIG_DIR = userDataPath;
          } else {
              await mkdir(userDataPath);
              process.env.THEIA_CONFIG_DIR = userDataPath;
              this.pathExistenceCache[userDataPath] = true;
          }
      } else {
          process.env.THEIA_CONFIG_DIR = join(homedir(), '.theia');
      }
      return FileUri.create(process.env.THEIA_CONFIG_DIR).toString();
  }

Steps to Reproduce:

if process.env.THEIA_CONFIG_DIR is specified as a directory, the latest cache file address is not matched

Additional Information

JonasHelming commented 2 months ago

@xai FYI

xai commented 2 months ago

@JonasHelming, please assign this issue to me (cannot self-assign). Thanks!

xai commented 2 months ago

I understand that there should be a priority order where:

1. User-defined settings take precedence,

2. Followed by application-specific settings if defined,

3. Lastly, defaulting to the standard THEIA directory if neither is provided.

Thank you very much @fanyipin for raising this issue!

My understanding here is the same, so I opened PR #13708, which ensures the 1. property, that is currently violated.