9
$\begingroup$

Bug introduced in 10.2 and fixed in 11.1


I have found that LocalSymbol will sometimes create and store persistent data in a directory different from and off the path of the one specified in its second argument.


Contents of a notebook demonstating the problem

I created a directory Test Folder on my desktop and saved the notebook the content of wto it as 'test.nb.

NotebookDirectory[]

"/Users/oldmg/Desktop/Test Folder/"

I then made a local symbol.

LocalSymbol["testData", NotebookDirectory[]] = "Hello, world";

LocalSymbol has no problem in retrieving the data.

LocalSymbol["testData", NotebookDirectory[]]

"Hello, world"

However, the data is not stored in the directory specified.

FileExistsQ[FileNameJoin[{NotebookDirectory[], "testData"}]]

False

Here is the directory structure that was created.

folder


I am disturbed by this behavior. It is important to me that all the files belonging to one of my projects be stored in the directory of my choice.

This behavior raises two questions.

  • Why does Mathematica do this?
  • What work-arounds might be used to ameliorate its effects?
$\endgroup$
  • $\begingroup$ Did you report the problem? $\endgroup$ – Szabolcs Aug 23 '16 at 14:50
  • $\begingroup$ @Szabolcs. I see you added bugs. I can't agree that this post should have that tag. Please consider removing it. $\endgroup$ – m_goldberg Aug 23 '16 at 18:43
  • 1
    $\begingroup$ I think it should still be reported. Reporting is not complaining. It is giving them a chance to fix things. There is no harm in it. Just let them decide if it's a bug or not. I still strongly suspect that this behaviour can cause serious problems. On Windows, it is very common for usernames to have spaces in them. The system even encourages you to use your full name as a login name, "Firstname Lastname", which is bound to have a space. $\endgroup$ – Szabolcs Aug 24 '16 at 7:52
  • 1
    $\begingroup$ If a username has a space in it then $LocalSymbolBase has a space in it too. What will happen then? Will Mathematica start creating directories with a + in the name in C:\Users? That would certainly be a serious bug! I cannot test this because on the Windows computer which I occasionally have the chance to use I already changed the username to have no spaces. When it did have spaces before, it caused problems with some ported Unix tools. But a proper Windows application like Mathematica should not be tripped up by a space in the username. $\endgroup$ – Szabolcs Aug 24 '16 at 7:52
  • 1
    $\begingroup$ Also, I really don't see any evidence that this would be a considered design decision. file:/// paths are more common in v11 and have no issues with spaces. The documentation also says that LocalSymbol[relpath, File["path"]] is valid, which makes it pretty clear that the second argument can be any local file system path. (Note: adding File won't fix the problem.) To me this is clearly a bug. But since we disagree, I would prefer not to touch the tag myself anymore and let someone else handle it. $\endgroup$ – Szabolcs Aug 24 '16 at 8:05
6
$\begingroup$

I suspect what I have encountered has to do with LocalSymbol sharing code with CloudSymbol. Internally the argument given to LocalSymbol is transformed into the form "file:///\[Ellipsis]", and because spaces are not allowed in URLs, the directory name is changed to eliminate the spaces.

My theory gets strong support from the following evaluations:

LocalSymbol["hello"] = "Hello, world"; 
LocalObjects[]

{LocalObject["file:///Users/oldmg/Library/Wolfram/Objects/LocalSymbols/hello"]}

Note that the results shows a file URL and the default directory path used by Mathematica is carefully constructed not to contain any space in the directory names.

The theory gets further support from my having determined that LocalSymbol will behave itself if I refrain from using spaces in the names I give to my files and directories.

Work-arounds

  • Refrain from using spaces in the names I use for files and directories which I for my Mathematica projects.

  • Create my own master directory for project-related local symbols. Obviously, I can structure such a directory any way I want to.

  • Use ~/Library/Wolfram/Objects/ to store persistent data, but create my own directory there for storing my project related stuff. This is a variant on the previous work-around.

Each of these work-arounds has its advantages and disadvantages. I have not yet decided which way I will go.

$\endgroup$
4
$\begingroup$

UPDATE: both problems described below aren't present in version 11.1.1


Szabolcs is absolutely right:

I still strongly suspect that this behaviour can cause serious problems. On Windows, it is very common for usernames to have spaces in them. The system even encourages you to use your full name as a login name, "Firstname Lastname", which is bound to have a space. If a username has a space in it then $LocalSymbolBase has a space in it too. What will happen then? Will Mathematica start creating directories with a + in the name in C:\Users? That would certainly be a serious bug!

For the check I have created a new account on my computer (running Windows 7 x64) with name "user with a space" and granted it Administrative rights. Then I opened Mathematica 11 under this new account, saved Notebook to Desktop and evaluated the following:

LocalSymbol["testData", NotebookDirectory[]] = "Hello, world";

On the Desktop I got no new files but here is how the system folder "Users" now looks on my machine:

screenshot

As one can see, a new folder with name "user+with+a+space" is created in the system directory! This directory is not intended for modification by users or third-party programs, and only Administrators by default can create subdirectories here. So I'm sure the current behavior is a serious bug.

Here is the value of $LocalSymbolBase:

$LocalSymbolBase
"file:///C:/Users/user+with+a+space/AppData/Roaming/Wolfram/Objects/LocalSymbols"

Now I switched back under my main account with name "user" and created on the Desktop a folder with Cyrillic name "Папка", saved a Notebook there and evaluated:

LocalSymbol["hello", NotebookDirectory[]] = "Hello, world";

Near that folder I get a folder with name "%D0%9F%D0%B0%D0%BF%D0%BA%D0%B0". So obviously LocalSymbol currently also has problems with non-ASCII filepaths.

$\endgroup$
  • $\begingroup$ Does it still create this directory if you simply use LocalSymbol["x"] = 123, without a second argument? $\endgroup$ – Szabolcs Aug 24 '16 at 10:36
  • $\begingroup$ @Szabolcs Yes, it does. See also update about $LocalSymbolBase at the bottom of the answer. $\endgroup$ – Alexey Popkov Aug 24 '16 at 10:46
  • $\begingroup$ Looks like more of a problem on Windows than it is on OS X. On OS X user login directories can't have spaces in their names; they must be Unix short form names. $\endgroup$ – m_goldberg Aug 25 '16 at 0:45
  • $\begingroup$ @m_goldberg What is about non-ASCII filepaths on OS X (an example is in the last section of the answer)? $\endgroup$ – Alexey Popkov Aug 25 '16 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.