How can one trace the content of a directory? The directory here refers to non home and non current directory. Explicitly, I have three directories
10.5.8 - current directory
Development
Backup
So, how can I undergo file operation like create, accessing or deleting on Development or
Backup directory other than my current directory?
Regards,
Lenin
Your terminology is hard to understand. Do you mean you want to monitor a folder (and its children) for changes, read/modify folders/files to which you don't have permission, or both?
To monitor for changes, check out the FSEvents API.
To obtain permission to perform a privileged operation, check out the Authorization Services API.
Related
I'm using FSEvents APIs to detect file system changes for backup application. Application creates a FSEvent stream on ROOT (/) path. Now the problem starts if sombody removes a file via shell with different case/normalization. Let say if folder (/Users/bob) contains a file called a.txt and user deletes it with A.TXT, under this situation event will generate against path /Users/bob/A.TXT rather than /Users/bob/a.txt.
At this moment backup application has no clue about the case of deleted file (under HFS+ and APFS). From 10.13 onwards APFS is the default file-system for Mac devices and it preserve the normalization of file. So under APFS problem becomes more complex since application also clueless about the normalization of deleted file. In the developer docs I din’t find details about this. Ideally delete event should preserve the case and normalization of file.
Any insight on this is appreciated.
I want to store a JSON to the file system. Where should i store the files so that the user can't see/delete them and that the files won't be deleted after a phone reboot/restart?
ApplicationData The directory for application data specific to the user executing the program. On non-Windows operating systems, this
path is the value of the environment variable XDG_CONFIG_HOME if it is
set, otherwise the ".config" directory in the current user's home
directory.
CommonApplicationData The directory for data shared by applications. On non-Windows operating systems, the "/usr/share"
directory.
LocalApplicationData The directory for application data shared by users of the computer. On non-Windows operating systems, this path is
the value of the environment variable XDG_DATA_HOME if it is set,
otherwise the ".local/share" directory in the current user's home
directory.
Personal The personal or home directory for the current user. On non-Windows operating systems, this is the user's home directory.
Source: System.Environment.SpecialFolder
I don't understand what Personal is for exactly, but on most sites on the web i found people using it. Should i use one of these or am i looking at the wrong things?
And for storing at the moment (May 2017) my only two options are SQLite and PCLStorage.
You can use any of the below folders for your requirements. If I understood your questions correctly you want only the app to be able to access (create/updated/delete) certain files which should be preserved on phone reboot or restart and the user shouldn't be able to access the files. You can use any of the below special folders:
Environment.SpecialFolder.ApplicationData is $HOME/.config, which maps to /data/data/#PACKAGE_NAME#/files/.config.
Environment.SpecialFolder.LocalApplicationData is $HOME/.local/share, which maps to /data/data/#PACKAGE_NAME#/files/.local/share.
Environment.SpecialFolder.Personal is $HOME, which maps to /data/data/#PACKAGE_NAME#/files
Looking at the description and mapping to the file system, for saving a JSON file I would probably pick Environment.SpecialFolder.ApplicationData, but there seems to be nothing wrong in picking either of the three based on how they map in the file system.
Notice that all these paths are within the specific directory for your app package so no other apps will be able to access these files. And neither will you be able to access them from any file system (unless the phone is rooted).
If you want more information on any file path, you can iterate through them, like this:
static void PrintFolderPath(System.Environment.SpecialFolder folder)
{
Console.WriteLine ("{0}={1}", folder, System.Environment.GetFolderPath(folder));
}
More reading: https://forums.xamarin.com/discussion/3773/system-environment-specialfolder
Context
I am trying to have the resources directory of a project sync itself to Google Drive as a means of backup, without having to physically move it into the Drive folder, and while maintaining full tab completion and access via the terminal from within the project. I'm on OS X.
The project is stored in a separate portion of my filesystem dedicated to GitHub repos, but I don't want to store all of the media (it's a vision project) on GitHub.
Now, the simplest solution is to alias the resources directory, move the original to the Drive Folder and access it via the alias within the project. However, accessing the resources via an alias in the terminal appears to break not just tab completion, but actual access to the media...
Eg: ./program input=resources/video.mp4
...where resources is an alias of Drive/resources, fails. And I'm afraid my understanding of aliases, symlinks and hardlinks isn't deep enough to see why.
Questions
Is there a way to sync the a directory to drive without physically moving the original directory to Drive/, such that I can leave my project filesystem untouched.
OR
Is there a way to maintain normal path behaviour and tab completion with an aliased directory? eg: ./program input=Project/res_alias/video.mp4. If so, the Drive issue is null and void.
Hi I am trying to find out what is the best location to save a cache file.
I have an Windows form application that updates user's data from the server using a custom tool.
I want to write the timestamp of the latest updates done on user's machine in the cache file.
Where is the best location for keeping this file:
1. in application directory (c:\program files..)
2. in a temp location e.g. Users profile folder or c:\windows\temp
3. in any location (e.g. c:\dataupdates) where user has full access to read/write to.
Not in the application directory. That much is clear. :) The application directory shouldn't even be writable by the program (or actually by the user account that runs the program). Although some applications still use this location, it has actually been deprecated since Windows 95, I believe, and it has become a real pain since the more rigid UAC applied in Windows Vista and 7.
So the most obvious options are:
The temp folder, which is for temporary files. Note however, that you will need to clean those files up. Temp folder is not automatically cleared by default, so adding new files all the time will consume increasingly much space on the hard drive. On the other hand, some users do clear their temp folders, or may have scripts installed that do that for them, so you cannot trust such files to remain. Also, this is not always C:\Temp of whatever. You'll have to ask Windows what the location is.
You can pick 'any' location. Note that you cannot write anywhere. You cannot even expect the C drive to exist. If you choose this, then you have to make it a configurable setting.
The %app data% directory, my personal favorite, which is a special directory for applications to store their data in. The advantage is, that you can ask Windows for this location, and you can make up a relative path based on that directory, so you don't really have to make it an application setting. For more info on how to get it, see also this question: C# getting the path of %AppData%
I would definitely choose the App Data path for this purpose.
Is it possible to lock a directory in Windows so as to ensure that no other process is reading or modifying files inside the directory for the duration of the lock, while at the same time allowing the process with the lock to modify and move files and directory itself freely?
This is not a real answer, but as a workaround:
Move the directory to a subdirectory specific to your application, which is on the same volume.
Advantages:
Prevents users and other programs from modifying the file at the old location, as the files will no longer be there
Importantly, will fail if a process already has a file open within that directory, thus ensuring that the "acquired" lock is indeed "exclusive"
Disadvantages:
It's a hack
The software will need to be adapted to work with the directory at a different path than where it was initially
Users and programs attempting to access the files will encounter unusual behavior or errors ("Path not found" instead of "Access denied")
Does not protect against programs that may poke into your application-specific subdirectory
Will leave the directory "locked" (moved to a location the user probably can't find) if your program crashes while the "lock" is "held"