IPFS: Symbolic links in MFS - ipfs

Is there a symlink equivalent for IPFS's Mutable File System? For example, if I have a file:
/source/file.txt
and I copy it another folder:
ipfs files cp /source/file.txt /reference/file.txt
the two files will refer to the same object. If I make a change to /source/file.txt the copy in /reference/file.txt will still point to the old version. Is there a good way to make it point to the current version of the file in /source/?
I could keep track of all the copies and update them whenever I change the original, but that doesn't sound fun. I could also store the string "/source/file.txt" in /reference/file.txt and manually dereference each time I want to access the file. Better, but still cumbersome. Are there any other options?

For the time being, there is no support for symnlinks in MFS: you need to track and update them manually in userland. Current MFS implementation uses immutable identifiers (CID) and each directory's CID is based on hashes of its children, so storing string in a file sounds like the most optimal way, as it does not trigger DAG recalculation every time you update the target file.

Related

How to make an Octave path root folder for all subfolders

I have a folder for Octave M-files in C:\\Users\Dropbox\Octave, under which are various subfolders by function categories (normal distribution, chisq...). I just started making those subfolders and they will keep changing (adding, removing, reshuffling) as time goes on.
I would just like to set that folder as root and have Octave search for functions recursively there, just like you set a classpath in Java and JVM searches all folders there.
I used addpath(genpath('C:\\Users\Dropbox\Octave')), but the paths generated are then fixed, not reflecting subsequent subfolder changes.
Shall I add addpath(genpath('C:\\Users\Dropbox\Octave')) to the .octaverc file?
I think there is some confusion here. There are several ways to interact with the path, but for the most part these do not result in permanent changes, unless you save this somehow.
Simply adding a path for an existing octave session will not result in any permanent changes to the usual path that octave initialises at startup. Therefore when you say:
I used addpath(genpath('C:\Users\Dropbox\Octave')), but the paths generated are then fixed, not reflecting subsequent subfolder changes.
this makes no sense, because as soon as you exit your octave session, those added paths should have been gone altogether, and not appear in later octave sessions.
It is more likely that at some point you added these paths, and then used the savepath command, which resulted in your custom paths being added to your .octaverc file.
If that is the case, then yes, you can expect that octave will not "update" what was written in your .octaverc file, unless you call savepath again with an updated path definition.
If you would like the addpath(genpath('C:\Users\Dropbox\Octave')) command you mentioned to be called every time octave starts, so that the current/updated directory structure is loaded, then yes, the best way to do it would be to add that command to your .octaverc file. Make sure you remove the lines in your .octaverc that refer to the previous changes made by savepath. Note that there may be several levels of octaverc files that you need to check (see the relevant page in the manual)
Alternatively, you could simply make sure that this line appears in every script you want to call which intends to make use of those files.
While you may consider this last approach tedious, programmatically it is the most recommended one, since it makes dependencies clear in your code. This is especially important if you ever plan to share your code (and doubly so if you'd like it to be matlab compatible).
PS. All the above mostly applies to matlab too, with the exception that a) matlab's savepath saves path information in a file called pathdef.m, rather than directly in your startup files, and b) matlab uses startup.m instead of .octaverc as startup files. Also, if you don't care about doing this programmatically, matlab provides pathtool, which is a graphical interface for adding / saving directories to the matlab path.

Store files in database with DBIC using Catalyst

I'm using Perl Catalyst framework to build an application that needs to store several files in a MySQL database (among other things). I want to store the name, path, extension, etc of the files to retrieve them later; because they are supposed to be accessible from the application (e.g: a PDF document uploaded for someone, must be available for download later). Can I do this? I found several ways to do it in PHP, but none for perl. Any ideas?
EDIT
I know I can access to some information using Catalyst::Request::Upload. I used this in the past for BLOB storage, but I dont't know how to get file information nor how to know where does catalyst store tmp files.
So, basically, the questions that arise when trying to this are:
How to know where are my files being stored once I submit them?
How to copy these files (which I assume go to a tmp folder somewhere) to a folder in my computer/server?
How to retrieve these files once I have them stored?
EDIT 2
I've checked again the documentation for Catalyst::Request::Upload (http://search.cpan.org/~jjnapiork/Catalyst-Runtime-5.90114/lib/Catalyst/Request/Upload.pm) and found out how to know where are my files being stored and how to copy them to a new non-tmp location. The only question that remains:
How do I generate a download link for these files??
The solution was pretty straight-forward.
First Make sure your 'tmp' folder is configured in the Catalyst app file (e.g: MyApp.pm).
Now, use Catalyst::Request::Upload to create the file object with the uploaded file. Sort of...
my $upload = $req->upload('input_field_name');
Now make sure you get all the data you want to store from the file. I, personally, got just the filename, MIME Type and size.
my $filename = $upload->filename;
my $size = $upload->size;
my $type = $upload->type;
Store into the database.
Now, create a folder within the public content of the page to copy the files to, and perform the copy like:
$upload->copy_to('path/to/the/public/folder');
To retrieve the files, just create a link with the base URL to the public folder and the filename you stored in the database.
Hope it helps someone... it was pretty obvious, though; but it cracked my head a little.

chrome.filesystem: Rename a file and save it on the client's disk

How could I do with chrome.filesystem to rename a file and save it. For example, if my file is named myfile.txt I would rename the myfile.html and save it without using the saveAs function. And if that's not possible, do I have a solution.
The problem is that I have to save the file on the client's disk. So for me to use the filesystem functions can not be a solution, I have not seen that chrome.filesystem API that allows.
Thank you in advance! I'm a little discouraged. I also watched the browserify aside to work around the problem, but I have not found how to do it.
To rename a file you must have the ability to create a new file on the user's filesystem. You can get this permission by asking the user to open the whole directory in which the project exists. Then you can create any file you want within that directory by calling getFile with { create: true } on the resulting DirectoryEntry.
Edit: See this example for duplicating files selected by the user. Instead of using fs.root as is done here you can use the result of chrome.fileSystem.chooseEntry as the DirectoryEntry in which the file is saved.

Is there any easy way to get folderID based on a given path?

Box api is implemented to be RESTful. and most supported methods are based on ids, folder_id or file_id.
As a very beginning start point, a root folder id, 0, stands for the root directory /All Files/.
from there (fold_id = 0), I can loop through all sub folders and find folder id for certain target folder.
or I can send search request to "https://api.box.com/2.0/search?query=target_folder_name", and process the response to locate target folder.
The former approach may need multiple list-folder-item requests, and the latter approach might be slow because the search is not just for folder/file name but also for other attributes of folder/file and even file content.
I am wondering if there is an easy way to find folder id for certain folder with a given path, such as "/All Files/MyFolder_A/Project_11".
Thank you very much for any help.
To the best of my knowledge, walking the folder tree (as you've suggested) is still the fastest way to get the ID of a particular file/folder. (See also this question: Get file ID of a given path.)

Is it possible to retrieve a file or folder resource by path?

Is there any way to get information about a file or folder on Box, given it's full path, but not ID?
For example, I'd like to check if /Foo/Bar/test.txt exists on Box. Currently, I have to start at the root and recursively walk through each folder level, searching for the next segment in the path.
As you can imagine, this process is very cumbersome when writing fully asynchronous code.
There currently is not a way to retrieve files or folders by path. This is something we may consider for the future, but don't have plans to implement it in the short term.