Poco::File .remove(bool recursive = false); should have option .remove(bool recursive = false, bool preservetopdir); - poco-libraries

A POCO request. I have a situation where a directory cannot be deleted (access rights), but the content is mine. I can call Poco::File .remove(true) on this directory which does indeed delete all the content of the directory, but the call always throws an exception as the dir itself cannot be deleted. So I have to frustratingly parse through the directory and remove each item individually. A simple "preserve the top level directory" parameter would make my day.
If anyone hears this and agrees, thanks!!

Related

I want my modPath variables to be from one directory

I want my modPath variables to be from one directory, is the following correct? Using C#. Thank you ^^
private readonly string modPath = #"C:\Users\SusanPeter\Mods";
if (string.IsNullOrEmpty(modPath))
{
MessageBox.Show("Sorry wrong directory");
return;
}
I am a beginning, learning to Write a program to check whether this particular Path (C:\Users\SusanPeter\Mods) is valid, and as long as not empty.
If this program is not placed in (C:\Users\SusanPeter\Mods), it will prompt for a message. I am sort of ensuring the path is correct before starting the program.

Default datapath of tessdata folder

I found a strange issue like even If I explicitly mention the datapath to be /data/local/tmp/tesseract/, the TessBaseAPI uses the tessdata inside /data/data/tesseract/ (Only if it exists). If tesseract directory does not exist inside /data/data folder then the given path is taken.
I almost searched the entire TessBaseAPI.java file, but I couldn't find the default path.
Following are the code:
String TESSBASE_PATH = "/data/local/tmp/tesseract/";
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(TESSBASE_PATH, "eng");
Can you please let me know from where the default datapath is taken?
There's no "default" data path. Only the path supplied to the init() method is used. Check out the code for the init() method--you'll see where the API throws an IllegalArgumentException if the data file is not in the specified location.

Swift: fileExistsAtPath returning TRUE

I'm experimenting a weird issue detecting if a file exists or not.
I'm working with SQLite, so I have a DB file in my App, which is Member of my Project in Target Membership, it's only the DB structure.
In my AppDelegate I'm checking if the file exists:
let fm = NSFileManager.defaultManager()
var docDir = ""
docDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let dbName:String = String.fromCString("db22.sqlite3")!
let path = docDir.stringByAppendingPathComponent(dbName)
In that point the file is created (not the idea), when I print the path, the file exist with size 0.
println("Database path: \(path)")
-rw-r--r-- 1 LLL staff 0 Jan 24 22:49 /Users/LLL/Library/Developer/CoreSimulator/Devices/F18F613D-B032-4B0A-87FC-3E484FC0C024/data/Containers/Data/Application/74FE784B-F131-4C60-9846-21D115E08594/Documents/db22.sqlite3
Just before run the app:
$ find /Users/LLL/Library/Developer/ -name db22.sqlite3
Nothing there.
So my next if in order to check if the file exists or not, is always returning TRUE:
if !(fm.fileExistsAtPath(path)) {
...
...
fm.copyItemAtPath(from, toPath: path, error: &error)
...
...
I tried with Reset Content and Settings in the Simulator, and also closing the project and deleting the all the files and directories in Library/Developer//Xcode/DerivedData/
But the results are the same (Product -> Clean also in XCode).
I was using this file before, working just fine, copying it to my DocumentDirectory in order to modify my DB, I deleted because I changed something in the tables, and suddenly was not working anymore.
If I tried changing the name dbName variable to something that I've never used before, then the file is not created, and the fileExistsAtPath is returning FALSE, as it should be doing also with the previous one.
I also deleted the db22.sqlite3 from my XCode Project, I cleaned and Cleared all the settings, deleting all the files in DerivedData...but the same result.
Any ideas?
Thanks in advance guys!

Laravel/blade caching css files

I am working on Nginx server, with PHP-FPM. I installed Laravel 4.1 and bootstrap v3.1.1., and here is the problem. For the last 30 minutes, I have been trying to change a css rule that I first declared to check boostrap.
.jumbotron{
background: red;
}
The first time it worked. The jumbotron container was red. So, I removed that css value and started working, but still no matter which browse I use, the container is red. I even checked the css file through the Google Chromes inspection tool, and it is showing me that first value when jumbotron had a background:red. I deleted the css file and renamed it and add new styles, I configured chrome not to cache pages. But Still the same value. I'm convinced now, that Laravel has kept a cache of the first style declaration.
Is there any way to disable this at all?
General explanation
When you access a Laravel Blade view, it will generate it to a temporary file so it doesn't have to process the Blade syntax every time you access to a view. These files are stored in app/storage/view with a filename that is the MD5 hash of the file path.
Usually when you change a view, Laravel regenerate these files automatically at the next view access and everything goes on. This is done by comparing the modification times of the generated file and the view's source file through the filemtime() function. Probably in your case there was a problem and the temporary file wasn't regenerated. In this case, you have to delete these files, so they can be regenerated. It doesn't harm anything, because they are autogenerated from your views and can be regenerated anytime. They are only for cache purposes.
Normally, they should be refreshed automatically, but you can delete these files anytime if they get stuck and you have problems like these, but as I said these should be just rare exceptions.
Code break down
All the following codes are from laravel/framerok/src/Illuminate/View/. I added some extra comments to the originals.
Get view
Starting from Engines/CompilerEngine.php we have the main code we need to understand the mechanics.
public function get($path, array $data = array())
{
// Push the path to the stack of the last compiled templates.
$this->lastCompiled[] = $path;
// If this given view has expired, which means it has simply been edited since
// it was last compiled, we will re-compile the views so we can evaluate a
// fresh copy of the view. We'll pass the compiler the path of the view.
if ($this->compiler->isExpired($path))
{
$this->compiler->compile($path);
}
// Return the MD5 hash of the path concatenated
// to the app's view storage folder path.
$compiled = $this->compiler->getCompiledPath($path);
// Once we have the path to the compiled file, we will evaluate the paths with
// typical PHP just like any other templates. We also keep a stack of views
// which have been rendered for right exception messages to be generated.
$results = $this->evaluatePath($compiled, $data);
// Remove last compiled path.
array_pop($this->lastCompiled);
return $results;
}
Check if regeneration required
This will be done in Compilers/Compiler.php. This is an important function. Depending on the result it will be decided whether the view should be recompiled. If this returns false instead of true that can be a reason for views not being regenerated.
public function isExpired($path)
{
$compiled = $this->getCompiledPath($path);
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( ! $this->cachePath || ! $this->files->exists($compiled))
{
return true;
}
$lastModified = $this->files->lastModified($path);
return $lastModified >= $this->files->lastModified($compiled);
}
Regenerate view
If the view is expired it will be regenerated. In Compilers\BladeCompiler.php we see that the compiler will loop through all Blade keywords and finally give back a string that contains the compiled PHP code. Then it will check if the view storage path is set and save the file there with a filename that is the MD5 hash of the view's filename.
public function compile($path)
{
$contents = $this->compileString($this->files->get($path));
if ( ! is_null($this->cachePath))
{
$this->files->put($this->getCompiledPath($path), $contents);
}
}
Evaluate
Finally in Engines/PhpEngine.php the view is evaluated. It imports the data passed to the view with extract() and include the file with the passed path in a try and catch all exceptions with handleViewException() that throws the exception again. There are some output buffering too.
Same issue here. I am using VirtualBox with Shared Folders pointing to my document root.
This pointed me in the right direction:
https://stackoverflow.com/a/26583609/1036602
Which led me to this:
http://www.danhart.co.uk/blog/vagrant-virtualbox-modified-files-not-updating-via-nginx-apache
and this:
https://forums.virtualbox.org/viewtopic.php?f=1&t=24905
If you're mounting your local dev root via vboxsf Shared Folders, set EnableSendFile Off in your apache2.conf (or sendfile off if using Nginx).
For what it's worth and because this answer came up first in my google search...
I had the same problem. The CSS and JS files wouldn't update. Deleting the cache files didn't work. The timestamps were not the problem. The only way I could update them was to change the filename, load it directly to get the 404 error, and then change the name back to the original name.
In the end the problem was not related to Laravel or the browser cache at all. The problem was due to NginX using sendfile which doesn't work with remote file systems. In my case, I was using VirtualBox for the OS and the remote file system was vboxsf through Guest Additions.
I hope this saves someone else some time.
In Laravel 5.8+ you can use so:
The version method will automatically append a unique hash to the filenames of all compiled files, allowing for more convenient cache busting:
mix.js('resources/js/app.js', 'public/js').version();
After generating the versioned file, you won't know the exact file name. So, you should use Laravel's global mix function within your views to load the appropriately hashed asset. The mix function will automatically determine the current name of the hashed file:
<script src="{{ mix('/js/app.js') }}"></script>
full document: https://laravel.com/docs/5.8/mix

How do I recognize a symlink in Dart when dealing with the Directory class?

When I instantiate a Directory in Dart, and that file exists, how can I check whether the Directory is a real folder, or just a symlink?
The way you can recognize a symlink is if the path differs from the full path. Directory doesn't have fullPath() or fullPathSync(), but File.fullPathSync() works on directories. So you can do this:
bool maybeIsSymlink(String path) {
var fullPath = new File(path).fullPathSync();
return path != fullPath;
}
However this only works correctly when path is absolute, and none of its ancestors are symlinks. To work around that you can get the full path of the directory's parent, append the directory name and compare that:
bool isSymlink(String pathString) {
var path = new Path(path);
var parentPath = path.directoryPath;
var fullParentPath = new File.fromPath(parentPath).fullPathSync();
var expectedPath = new Path(fullParentPath).append(path.filename).toString();
var fullPath = new File.fromPath(path).fullPathSync();
return fullPath != expectedPath;
}
Note that I have not tested this, but I've dealt with symlinks a lot in Dart, and this should work. If pathString ends in '/' you'll have to remove it. I usually end up getting paths from a directory listing, so I track the expected path as I recurse down the directory structure.
You can see a special listDirectory() implementation that detects symlinks and sends Symlink instances to the stream along with Files and Directorys in a branch in buildtool: https://github.com/dart-lang/buildtool/blob/m4/lib/src/util/io.dart
In bleeding edge, there now is a static FileSystemEntity.isLinkSync(path) methods that will tell you if something is a symlink; also when it is a broken symlink.
http://api.dartlang.org/docs/bleeding_edge/dart_io/FileSystemEntity.html
For operations on links we are adding a Link class. The code is out for review now:
https://codereview.chromium.org/12691002
If you want to check from the command line to verify what is happening,
ls -al DIRNAME and check for 'l' in the permissions section, and examine what it's pointing "to" on the right side of the output.
see also man 1 stat
If you're wanting to check that from within Dart itself, I don't know how.
FileSystemEntity.typeSync(path)
return an FileSystemEntityType with one of the values
FileSystemEntityType.DIRECTORY
FileSystemEntityType.FILE
FileSystemEntityType.LINK
FileSystemEntityType.NOT_FOUND

Resources