NodeJS deletes one folder but fails on another identical one (EPERM: operation not permitted, rmdir) - node.js

I have a timelapse program that I wrote myself, using NodeJS. It takes a screenshot once per second while ever the computer is unlocked, and for each day it creates a new subdirectory named the current date. Thus I have a heap of directories like this:
The screenshot program runs at logon as the main user of the computer (using Task Scheduler).
I also have another NodeJS program that compiles the screenshot images into videos (using ffmpeg), and after the video is created it removes all files from within the directory and then removes the directory.
My problem is that for some reason while the compiling Node script successfully deletes the images inside each date-named folder, it's unable to delete the empty directories, failing with:
Error: EPERM: operation not permitted, rmdir 'E:\timelapses\daily\2020-04-10\'
Initially I thought it was a permissions issue, so I ran the video-compiler as administrator. No change, it still failed trying to delete the empty directory. Then I tried ensuring every date-named folder and the parent directory had Full control:
Still fails to delete! Getting frustrated, I created a simplified test script, literally just:
let fs = require('fs');
fs.rmdirSync('test');
fs.rmdirSync('test2');
The test folder is one I created myself (right-click > New > Folder), and the test2 folder is a copy (right-click > Copy > Paste) of one of the empty folders that NodeJS can't delete. Upon running that script the test folder instantly disappears but the test2 folder remains, and the script errors.
I'm so confused! Both folders look 100% identical in Properties, both are owned by me (the local user), both are Read Only.
What could be different? One folder was created by a regular Explorer window, the other by a NodeJS program. They're both appear identical as far as I can see. Both are totally empty as far as I can see (hidden and system files visible in Explorer, I see no files). The one that won't delete was a copy-paste, so it can't be held open by some program (and LockHunter shows no results). Are there some special, hidden attributes that I can't see?
In case it wasn't obvious, I'm on Windows 10. Node is v10.15.3 but the folder that refuses to delete was created with v8.16.1 (due to module incompatibilities).
Help!

Related

Create project that is not in the default path in DataSpell

I tried the new DataSpell today, but fail to create a project. Every time I try to attach a directory, it has been marked as a library. And it seems like the Project is always in
C:\Users\XXX\AppData\Roaming\JetBrains\DataSpell2021.3\projects\workspace
What's more, the intended project root folder (i.e., Test_2) is marked as a Module,
What's more, I can not mark the directory as well as all the subdrectories within it:
Does anyone know how to create a PyCharm like project in DataSpell?

Node : What is the right way to delete all the files from a directory?

So I was trying to delete all my files inside a folder using node.
I came across 2 methods .
Method 1
Delete the folder using rmkdir. But if I plan on adding the images on the same folder then I use mkdir and creates the same folder again and appends the files to it.
Example: I have an Add Files and Delete ALL button. When I click deleteAll , the folder gets deleted. And when I click add then the folder gets created and the file gets added to that folder
Method 2
Using readdir , I loop through the files and stores in an array and then delete only the files instead of the folder.
Which is the best way to do it ? If its not among these then please advice me a better solution.
The rm function of ShellJS will do the trick. It works as a one-liner, and it works cross-platform, and is well tested and documented. It even supports recursive deletes.
Basically, something such as:
const { rm } = require('shelljs');
rm('-rf', '/tmp/*');
(Sample code taken from ShellJS' documentation.)

Finding and saving present directory of a SAS-Studio-program in a Linux server

I am trying to make a macro variable in SAS Studio which saves the "present working directory" as a macro variable.
The SAS-program is run in a "CPF" process flow file in SAS Studio, and the whole SAS-file and processes are saved and run in a Linux server.
In SAS-Studio, the location of CPF-process flow file seems like in the directory /sasdata/model_v1, and when I run a Linux command like X "pwd" then I expect that the result will give /sasdata/model_v1, but I get another directory instead like /sasinstall/sasconfig/Lev1/SASApp instead, I guess the the process flow file with CPF-suffix is run from this directory.
So the question is how I can find and save the working directory of my cpf-file and save as a macro-variable, or even maybe for my other sas-files too, I may need the solution for both SAS-files and CPF-files.
If I find the directory, then I guess it should be enough to save them as macro-variable by using %let macrovariable = "/directory"
I don't think SAS will show you the path of the process file. It doesn't in SAS/Studio 3.5.
It will set the path for a normal program file (as long as you have saved it) in the _SASPROGRAMFILE macro variable.

Access test resources within Haskell tests

This is probably a basic question but I've been Googling for a while on it... I have a Cabal-ized Haskell project and I'm in the process of writing integration tests for it. I want to be able to include test resources for my project in the same repo and access them in tests. For example, here are a couple things I want to accomplish:
1) Check a dummy database instance into my repo, including a shell script that spins up a database process. I want to write an Hspec integration test that spins up the database process, makes some calls to it, and then shuts it down. So I need to be able to find the shell script so I can use System.Process.createProcess on it.
2) Check in paired "input" and "output" files. My test should process each of the input files and compare them to a corresponding output file to make sure they match. (I've read about "golden" but it doesn't seem to solve the problem of finding/reading the input files in the first place?)
In short, how can I go about creating a "resources" folder in the root folder of my Haskell project and find the path to it inside tests?
Have a look at an existing project that uses input and output file.
For example, take haddock, the source code is at https://github.com/haskell/haddock. They have the test files under a folder (https://github.com/haskell/haddock/tree/master/html-test/ref) and they are referenced as extra-source-files in the cabal file (https://github.com/haskell/haddock/blob/master/haddock.cabal). Then the test code (https://github.com/haskell/haddock/blob/master/html-test/run.lhs) uses some CPP macro (__FILE__) to get the current directory, and can then resolve the files relative to that folder.

Qt Installer framework - Copying files to location other than install directory

I know that, whatever data is placed in package/component dir/data, will be copied to the install directory. What I mean is if I have a binary, readme, license.txt inside package/component dir/data/myapp, package/component dir/data/readme, package/component dir/data/license.txt and if I choose my target installation dir to be “/opt/myfirstapp”, then inisde /opt/myfirstapp, I will have 3 files copied, myapp, readme, license.txt.
Having said that, I also have a “/usr” directory with in package/component dir/data/, however this is not the standard “/usr” which will be inside root “/”, it is just a replica. Now inside my replica “/usr” I have some directory hierarchy and some files, like /usr/bin/myapp, /usr/lib/libmyapp.so, /usr/share/icons” and many more, infact a lot. Now I want the replica “/usr” content to be copied to “/usr” (the original usr inside root folder). I should also make sure that I just add new contents to “/usr” (root /usr), but delete any existing content.
Question is clear, some files inside my data directory will have to go to target install dir, but some selected ones (for ex: /usr) will have to be copied to other paths. How do I achieve this.
Currently we have the same problem in my company: we need 2 target directories, one for the exe and one for the libraries (well, it's a bit more complex but in few words...).
After having spoken with Qt support and got the answer that it's actually not possible ("It is possible only after extracting. After extraction, you can use copy or move operation, unfortunately there is currently no other way.") I decided to use the AdminTargetDir as the second target directory. This because there's no other way to pass dynamic variables to the IFW. So after installation I call a "finalizeInstall_patch.bat" file passing the TargetDir and AdminTargetDir and this will move the libraries directory from TargetDir to AdminTargetDir. Why a .bat patch file ? because it's actually not possible to move a directory using the methods provided by the IFW. Qt support just opened a suggestion-ticket for our problem: https://bugreports.qt-project.org/browse/QTIFW-595
I hope that this answer will help others having same similar problems.
NOTE: There is a way to move a directory (on Windows), calling addOperation("Execute", "cmd /C move source dest...") but this brings to other problems out of topic here.
This worked for us (Qt Installer, macOS):
var args = ["cp", "-R", "#TargetDir#/MyApp.app", "/Applications"];
component.addOperation("Execute", args);

Resources