Skip to content

Cannot Open Folder Suffixed ".Template" on macOS #247974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gilmorem560 opened this issue May 1, 2025 · 8 comments
Open

Cannot Open Folder Suffixed ".Template" on macOS #247974

gilmorem560 opened this issue May 1, 2025 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member electron Issues and items related to Electron upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@gilmorem560
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.99.3
  • OS Version: Darwin 24.3.0

Steps to Reproduce:

  1. Create any directory suffixed ".Template"
  2. Attempt to open this directory via File->Open Folder in VSCode

When performing these steps, the Open Folder dialog closes but no visible change occurs in the VSCode application, it simply remains on whatever was already open, neither opening the new folder nor giving any sort of feedback that it did not do as requested.

Worth noting, opening said directory by passing it as an argument to "code" on the command-line does work, so the path is a standard UNIX directory listing out a series of files that can be viewed in the file tree in VSCode. For some reason it simply refuses to open if it is suffixed ".Template". This does not appear to happen outside of macOS.

@bpasero
Copy link
Member

bpasero commented May 5, 2025

I cannot reproduce:

Image

@bpasero bpasero added info-needed Issue requires more information from poster confirmation-pending labels May 5, 2025
@gilmorem560
Copy link
Author

Okay, more explicit, a folder with any other text suffixed ".Template", I didn't mean literally the name ".Template" but something like "Project.Api.Template" or "New.App.Template". Suffixed ".Template", not named ".Template".

@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member upstream Issue identified as 'upstream' component related (exists outside of VS Code) electron Issues and items related to Electron and removed info-needed Issue requires more information from poster confirmation-pending labels May 12, 2025
@bpasero bpasero assigned deepak1556 and unassigned bpasero May 12, 2025
@bpasero
Copy link
Member

bpasero commented May 12, 2025

I can reproduce in a fiddle, it seems when treatPackageAsDirectory is set, selecting a xy.template folder does not return that path:

const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');

app.whenReady().then(() => {
  const win = new BrowserWindow({
    width: 600,
    height: 400,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
    }
  });

  win.loadFile('index.html');

  ipcMain.handle('select-folder', async () => {
    const result = await dialog.showOpenDialog(win, {
      properties: [
        'openDirectory',
        'treatPackageAsDirectory'
      ]
    });
    console.log(result);
    return result.filePaths[0] || null;
  });
});
<!DOCTYPE html>
<html>
  <body>
    <h2>Select a Folder</h2>
    <button id="selectBtn">Choose Folder</button>
    <p id="path"></p>

    <script>
      document.getElementById('selectBtn').addEventListener('click', async () => {
        const folderPath = await window.electronAPI.selectFolder();
        document.getElementById('path').textContent = folderPath || 'No folder selected';
      });
    </script>
  </body>
</html>
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electronAPI', {
  selectFolder: () => ipcRenderer.invoke('select-folder')
});

@gilmorem560
Copy link
Author

It's tricky to ID at what layer the problem is, whether it's directly in VSCode (seems growingly unlikely), Electron (possibly), or even just a limitation down in Cocoa's file selection dialog. It does seem Apple has a special idea of what ".Template" means at the end of a path whether the file itself is a regular file, directory, whatever else, similar to the ".app" suffix on application packages. In any case, now that I've looked at it a bit more this certainly seems related to that macOS-specific treatment of certain suffixes.

Supporting this is another case I tried, I created a directory on my desktop named "test.app" to see what another one of these special directory suffixes would do, and in this case I can't even select the directory, Apple has decided if a path name has ".app" at the end, as a user thou shalt have no choice to open it as a directory:

Image

Needless to say the root cause is probably this "my terms, not yours" approach by Apple on directories, a clear violation of the UNIX philosophy underlying the XNU/Darwin OS.

Anywho, good luck, if nothing else, glad I could raise awareness of the issue.

@bpasero
Copy link
Member

bpasero commented May 12, 2025

@gilmorem560 but we explicitly set a flag to allow for drilling into .app folders so that you can open things inside, that should work in VS Code.

@gilmorem560
Copy link
Author

gilmorem560 commented May 12, 2025

Unfortunately that test doesn't, although if I had to wager a guess it's because it's literally just a directory, not a true ".app" as Apple defines it, so Cocoa probably says POSIX definition of a directory be damned, we're going to set the terms, not you.

Edit: Just tried another, ".bundle", this one behaves similarly to ".Template" in that it is clickable in the file open dialog, but doesn't do anything.

@deepak1556
Copy link
Collaborator

.Template and .app are package types on macOS. The behavior change with electron/electron#38557 to align with Chromium to not allow choosing files or packages when openFile is not set. You can see this difference when using File > Open... vs File > Open Folder... in VSCode whether the former allows opening package file types.

However, this is a bug in Electron since there is an option to allow to treat package apps as directory and it should be respected in this check that regressed this behavior.

@deepak1556
Copy link
Collaborator

Addressed in electron/electron#47077

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member electron Issues and items related to Electron upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

5 participants