Save file with windows path system in linux file structure - linux

My spring application is running on a tomcat server under Windows system and saves files to path C:\pathtoSav (file = new File("C:\upload\" + filename)).
I want to migrate my application on a tomcat server under Linux system.
Can I create this file with path on Linux system without change my code.

You will need to change your code. You have a few options:
Use a relative directory such as saving the file to the current directory. This will work on both systems.
Check the operating system using something like System.getProperty("os.name") and hardcode the path to what you need in each system (e.g. C:\upload in Windows and /home/ubuntu/uploads in Linux), selecting which one you want based on the OS.
Find a way to get a reasonable path on any OS, such as System.getProperty("user.home") which will always return the user's directory for the operating system.
If you need to build paths yourself, Java has File.separator as a convenience, which will be a forward slash on *nix and a backslash on Windows.

Related

Where to put Files for Mono Application in Unix

I am writing a C# application (in Visual Studio on Windows) that will be run as a mono application on Unix (Raspbian aka Debian). I am a Unix noob, and though I have read (well, skimmed) the Linux Foundation Filesystem Hierarchy Standard I am still not completely clear on where I should put the files my application will need. I have:
The compiled C# application (app.exe). I thought I would put this in /usr/bin, except that the application is not run directly (it is invoked by "mono app.exe"), so maybe /usr/libexec is a better location?
Configuration files (there may be more than one) (app.1.conf, app.2.conf, etc.). If they are not user specific, I would think /etc/app (a directory, not a file) would be a good place for these. How about if they are user specific? /home/?
Log file (app.log). Seems that /var/log is the right place for this.
Thanks in advance for your input.
You should look at an already established Mono app for reference. For example let's take MonoDevelop:
The exe file goes to /usr/lib/{appnameinlowercase}/bin/ , but they place a launcher script in /usr/bin, named {appnameinlowercase}, for easy launch from the command line (this script just calls exec mono YourAppName.exe).
In .NET the config files need to be in the same directory as the executable file, so you could place them in /usr/lib/{appnameinlowercase}/bin, then later for convenience, put symlinks to them from /etc/{appnameinlowercase}/.
Correct, /var/log/{appnameinlowercase}/ should be fine.

How can I make a file "permanent" in a Linux live version?

I am working with a live Linux version. If I create a user and that user creates a file, how can I make that file visible for that user after I have restarted the system? (Normally it would be erased)
You can save the file in the device's hard drive, if you are using a CD/DVD.
In case you are using a flash drive, you can save the file in the root / folder.
Note: Be careful with name given in root folder, try to avoid things like boot or other names found in that folder. They are used to start the live system and boot manager usually recognize them based only in file names

Application installed with Inno Setup writes files to unknown location instead of its installation folder

I try to make a setup with Inno Setup for my program.
I have installed more file XML in the same folder as the .exe. The install work well, but when I run the program and modify the XML, the file is saved in another place, not the folder of the .exe and I can't find it. I think the file is stored in the PC because the program can open it without problems.
I also try to make the same setup with InstallAware Express 7 and it works well. Io I think it's not a problem in my exe but in Inno Setup.
Thanks
I think you are a victim of Windows File virtualization.
You probably install data files to Program Files folder.
That folder is not writable (unless your program runs with elevated privileges). If your program does not have application manifest, Windows considers it a legacy application that is not aware of its inability to write to Program Files and enables file virtualization. So, when your application tries to write the data/XML files, Windows redirects the write (and future reads) to a virtual store (C:\Users\username\AppData\Local\VirtualStore). The actual files in the Program Files are not modified.
It's difficult to answer, why it works with the InstallAware Express. If you tried it after the Inno Setup, the results can be affected by an existence of the file in the virtual store.
Anyway, the root cause is that your application tries to write the files in the Program Files. That's just wrong. No application should write to Program Files.
See also Application does not work when installed with Inno Setup.

Program data folders in Linux

This is a more general and noob question. I am developing a small application in Linux (Ubuntu, to be more precise) and at this point I have an executable, a shared library (.so), a configuration file (.conf) with some settings to be read by the application at the beginning, a data folder with images and other resources to be used during the application life-time (resources that can be also modified, deleted) and of course, I would need some file for logs and messages (right now I am using syslog).
So, my question is, where should each one of these be stored when the application is installed on a client's computer? What is the standard way of organizing all the application's files in Linux? On Windows everything would be found usually in the C:\Program Files\(App Folder) but it looks like on Linux things are more (or less) organized. Can you give me some advices on this matter?
Program data were historically stored in dot-prefixed folders in user's home directory. Modern Linux distributions tends to use ~/.config/program_name folder.
For all files that will not be modified after distibution follow Linux standard:
Ex: project dir: ABC
sub directories:
logs - keep log files
conf - keep configuration files here
bin - executable binaries here
traps - any trap mesg
then depend on what application we develop
Along with you can set level for starting your application from boot level if required.

Preserving permissions while copying from Windows to Linux

I gave execute permissions to a file and then compressed into a zip file in Linux OS. Then I moved this zip file to Windows and again copied it to another Linux server. This time I don't have the execute permission.
I know that we can directly copy the files and folders using scp command withing Linux but I have to let the user copy it from Windows to Linux also.
Please let me know how can I preserve the permissions while copying from Windows to Linux.
Thanks.
Since your executable file is inside a zip-archive it doesn't really matter what filesystem you're on or what operating system you're on. As long as the zip-archive is untouched.
However, as far as I know, zip-archives cannot keep track of file permissions. You can read more about it here:
Maintain file and folder permissions inside archives
It's up to whatever application is actually doing the copy.
But there are serious differences between the idea of file permissions on Linux/UNIX and Windows. UNIX file permissions have the idea of being "executable" which is not something that exists on Windows. Windows files are noted as runnable by their file extension not its permissions.
Furthermore, file permissions on UNIX have the concept of a group owner, and I don't think this exists on Windows so such a thing might not be possible in the strictest sense.
If you just want the writable/readable permissions as assigned to the owner to stick however, it will again depend on the application you are using to do the copy.
More recently, you can also use the Linux subsystem for Windows and zip the file using the linux shell command. I successfully did this recently when copying a executable for AWS from github to my Windows machine, and then up to Amazon.
Thanks for all your responses.
I found 2-solutions for my problem:
I am copying the complete zip file to the Linux server instead of copying a single file. This way it works fine.
Using cygwin helps me in copying the file onto a Linux server by preserving the execute permissions.

Resources