Cleanup Perl script should not delete a directory that is symlinked to - perl

A cleanup Perl script running periodically deletes old log files, and if the folder is empty, it deletes the folder as well. Unfortunately, there is one exception: it should not delete a directory that is symlinked to.

There's no way to tell if there exists a symlink that directly references a dir. (Same for indirect references.)
The best you could do is check every single file on the entire file system, but even that monumental effort wouldn't be perfect. For example, it won't find symlinks on devices that aren't currently mounted, it won't find foreign symlinks to shared portions of the file system, etc.

Related

Unable to write to a file created by an AutoHotKey script

I have a Dell PC with Win7 64 using what I believe is the latest version of AutoHotKey.
I wrote an Installer App with AutoHotKey to create two directories with a number of sub directories then install an exe program and a number of data files into those directories. The App installs into the existing C:\Program Files and C:\Program Data directories.
The Installer App creates the sub directory C:\Program Files\DSOSort then installs the file DSOSort.exe. The installer App then creates the sub directory C:\Program Data\DSOSort and installs a number of additional sub directories with all the associated text data files.
I used the FileCreateDir and FileInstall instructions in the Installation App to create the directories and install the files.
Everything in the Installer App and in the exe program works as it should except that the exe will not make any changes to the text data files in the newly created C:\Program Data\DSOSort directory. I have to open the directory with Properties and allow Users to Write. Once that is done the exe will change data in the text data files correctly and all is well.
If I change the Installer App to create a directory C:\DSOSort then install all the sub directories and data files in there instead of into C:\Program Data\DSOSort the exe can write to the text file. I do not have to change any permissions with Properties.
I tried using the various copies of the C:\Program Data\DSOSort directory I found in C:\Documents and Settings and also in C:\Users. The exe can read them but no Write.
I only have this problem with newly installed directories and again as I said earlier it can be corrected with Properties.
The exe program was written for people with enough knowledge to run the Installation App but do not understand Properties or making changes to the directories.
I could just leave the data files in a C:\DSOSort directory but would prefer to put them in a C:\Program Data\DSOSort directory.
Is there a way for AutoHotKey to check the user permissions and changing them if necessary before installing the data files?
Is my PC behaving properly? Is it supposed to create directories without allowing Write to the files?
Some of these directories, like "Program Files", require admin privileges to modify. I believe that is why you're experiencing that. Have your app run as an admin and it should be fine. The setting for you EXE can be found in the properties.
The A_IsAdmin built-in variable returns whether the current user has admin rights.

How can I safely clean up root's .cpan folder?

I have a development class Linux server which has been used for a great deal of Perl code creation and testing. On this machine is a /root folder, part of the / partition, and in there is a .cpan folder - which is currently consuming almost 1TB of disk space. We have been having issues with free space on the / partition and I'd like to 'clean up' this .cpan folder. The build sub-directory has 100's of sub-folders, which appear to be already installed CPAN modules. Is it safe to delete those? Is there an option/command I can use inside of cpan to check or assist in the clean up?
I've checked several man pages and on-line searches, but I'm not certain what could be removed without impacting the system. Are there setting I could change that would keep this folder clean in the future?
Thanks.
Short answer: Yes, you can delete that ~root/.cpan/build folder without affecting your system.
On the other hand: It's not recommended that user root has a .cpan folder at all. Usually you would install modules as some other (non-root) user. cpan then complains about not being able to install the modules in question and asks what to do. sudo is one option, I usually choose that. cpan will then compile and test new modules in that user's $HOME/.cpan and when it comes to installation it'll ask you for root's (or your) password (depends on settings in /etc/sudoers).
There's also a setting for the maximum size of the ~/.cpan/build directory. Run:
$ cpan
$ o conf build_cache
and see what the current setting is. For me it's [100] which means 100 MB. Type (e.g.)
$ o conf build_cache 50
$ o conf commit
to set it to 50 MB. The cpan shell will instruct you further.
I'm not perfectly sure but I think you need to run the clean command afterwards to actually reduce the size of ~/.cpan/build, i.e. (in the cpan shell):
$ clean
Just delete it.
All of the files in that directory are temporary files generated while installing or upgrading modules from CPAN. They are not required after the install is complete.
You may want to teach your system administrator about the cpanm tool, which is a bit easier to use, and does some automatic cleanup of its temporary files.
there is a process that will have high cpu usage if you delete the cpan folder. I forgot what process it is, but it scans files

How does operating system distinguish between file and directory

I was going through basics of File System implementation. While implementing for looking up for a file, how does the OS distinguish a file and the directory which it is in?
For example: If I want to lookup a file foo.c with the given path: /home/mac/work/foo.c, How does the OS decide home,mac and work are directories and foo.c is the file inside work directory
I will assume this question pertains to Linux operating systems.
A file by definition is at leaf-level of a tree. Therefore, anything that is suffixed with a / cannot be a file.
The leaf is another story. foo.c might be a file or it might be a directory. The OS has to look at it in order to determine which it is. Internally, a directory is technically a file, but it behaves differently.
To complicate things, Linux has soft- and hard-links, which are special files that can link to a file or directory. And indeed a directory might be the mount point for an entire file system. It's quite common to mount a separate partition or drive as /home. You don't really have to worry about these. You are mostly concerned with the addressing.
If you want to find out what a file is in Linux, use /usr/bin/stat.

Specifying a different temp directory for building install4j

When building on my linux machine, I notice that install4j creates directories in my /tmp directory. Unfortunately since my /tmp directory is on a small partition, it fills up quickly. Is there a variable I can specify to have these directories and files be in a different directory than /tmp?
Edit bin/install4j.vmoptions and add
-Djava.io.tmpdir=[path to temp dir]
on a new line.

Copy Directories Recursively From Ftp Server Using Perl

I need to write a perl script which has to log in to an FTP server and download all the sub-directories and contents on sub-directories to local machine. The version of Perl on the FTP server is 5.8.8, i can't upgrade it. One method is to create directories on local machine and then copy each file. I was wondering if there is any command to copy a directory and its content. Is it possible to "tar" the directory to save space?
Thanks,
Amit.
There is Net::FTP::Recursive. I haven't tried it but it seems to fit your requirements.