10

Do not silently ignore invalid arguments Your script allows to specify the source directory (and other locations). Here is the relevant part in function parseArgs(): -s|--src) if [ -d "$2" ]; then srcDir="$2" fi shift 2 ;; If --src <sourceDir> is specified ...


10

Instead of checking with an if statement if errStat is null and then returning false: if errStat != nil { return false } return true you can return a Boolean expression: return errStat == nil


8

Double-quote variables used as command arguments Although in many places in the posted code the variables used as command arguments are correctly double-quoted, there are more than a few exceptions, for example parseArgs $@, which should be parseArgs "$@" to preserve arguments with spaces. It's a good habit to systematically double-quote variables used as ...


6

General impressions - nice neat code, well commented. It's good that you use trap to clean up on exit. Shellcheck picks up a couple of oversights: 206596.sh:11:11: note: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. [SC2181] 206596.sh:22:1: warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164] 206596.sh:...


6

Bug You have a two bugs in get_digits_minimum_length(): if len(str(start_number)) > digits_length: digits_length = start_number First of all, you probably meant digits_length = len(start_number). But even that is not enough, because the end number might have more digits than the starting number. Therefore, it should be: digits_length = max(...


6

Others are better equipped than I to talk about the quality of the Python, but I can tell you that seeks are expensive, that all random reads cost about the same as long as you're reading less than a block, and that read+stat is worse than reading two sequential blocks, because the stat reads a directory and not the file. I see about a 10% speedup if you ...


6

Hello Suule and welcome to Codereview. What you can do is use a strategy pattern to say what to do in each case. This will not only allow you to reuse the "process" but also to decouple the monitoring and processing code. FileUtils.monitor(String directory, Consumer<File> action); class LogAction implements Consumer<File> { private final ...


6

This is what I meant in the comments You could do substr($hey,0,2) once and then check the first two letters instead of multiple strpos. Maybe, but I have no idea what $hey looks like :) - but than you could switch on that and get rid of the multiple function calls. I don't think it will be much faster, but with enough iterations, who knows, and it may ...


5

size_with_biggest_unit should be streamlined. Move the unit names into a list: unit_names = [ "", "KB", "MB", "TB" ] and iterate downwards: for exponent in range (4, -1, -1): if size > 1024 ** exponent: unit_name = unit_names[exponent] return str(round(size / 1024 ** exponent)) + unit_name raise ImpossibleError ...


5

Formatting The code formatting is good. The only major gripe I have is that there are some long lines (117 chars). Part of this is due to the high level of indenation, which we'll solve in another way, but even with heavily indented code, lines can be shorter. I use the black code formatter (with a linelength of 79) to format my code, so I don't have to ...


5

Elegance is the wrong criterion. The key criterion is correctness, which implies readability and maintainability. As you read text, you notice misspelled words. Does that mean that you laboriously spell-check each word, letter-by-letter? In fact, most likely, you quickly and unconsciously scan the shape of the words. Only if the shape of a word seems odd do ...


5

First, I'm afraid all the path handling and validation is a common anti-pattern of trying to check every conceivable error condition before trying to do something, in order to avoid lots of error-handling code. The problem is it doesn't work - it is literally impossible to guard against all possible errors, because an error may be introduced after you verify ...


5

Style feedback on how clear my comments were and how easy the code was to follow I'm not a big fan of line comments. I think they make the code a bit harder to follow. That's why I prefer tail comments along with a nice tabular layout of the labels, instructions, operands, and tail comments. And of course don't write redundant comments like "Update the ...


5

For what you are trying to achieve, Java has a very nice solution since Java 7: java.nio.Files. The Files class comes with a lot of useful methods that do what you did more expressively and easier to understand. Instead of listing all files in a directory and looping over them, you can actually walk the entire file tree, including sub-directories, if you ...


5

at first I thought to write this as a comment, perhaps the comment would be a little to long… There are many things to consider here, not really inline with your question but perhaps you should consider them. Transactional scope. You update the database, remove records… you may end-up orphaning the disk images where you have images that are not ...


5

Review Modelling the domain is crucial when designing a multi-layered application. Your concerns about polutting the domain with file or web specific code is pivotal to make a clean, extensible, reusable and testable API. I am finding it very difficult to think of a domain object which does not include FileInfo or FileStream. I would suggest the ...


4

Your code is clean, straightforward, and easy to follow. There is very little to comment on here. 1) You should consider using braces always. You don't have to, but they will save you a bug at some point (or you'll have to fix someone else's bug introduced into your code). 2) If you expect a result, enforce that result in your code: // Empty string does ...


4

If the file size is 0, it ignores that file (when it returns 0 from the size function and uses that to determine if the file is newer). I noticed this when testing it and I created an empty file and saw it was not mirrored. I would think the right behavior should be that it should copy the empty file. Also, it does not mirror deletions, if something is ...


4

This design does not convince me. You would achieve much better manintainability and testability when the buffering functionality would be implemented as a decorator. This is, create another logger that takes some other logger as a dependency and adds buffering on top of it. You would then be able to test it without having to actually log anything. You would ...


4

I spent sometime with the code you've currently posted @wizofe, I'm not sure if it'll ever be the same again... Side note; I heard it rumored that the character limits are just a bit more relaxed than on other sub-stacks... or in other-words this may get a bit verbose, or in other-other-words it could be another one of those posts so a snack and drink is ...


4

This is just a brain dump of some things about your code that I hope you find useful. Automated tools Automated tools can help you maintain your code more easily. The first ones I install whenever I start a new Python project, are: black — The uncompromising Python code formatter isort — A Python utility to sort imports flake8 — A tool to enforce PEP 8 ...


4

Don't use callbacks, it's hard to read and maintain, the fs.readdir function will return a promise if you didn't provide a callback function. Use arrow functions when you could. Respond with an error instead of throwing (unless you have a catch wrapper middleware). Use property shorthands. You forgot req and res. Try this: const express = require('express')...


4

Thank you for an interesting question 😊 Here is the first part of the answer, I will publish more over the weekend at https://github.com/dmitrynogin/shopless. Let’s talk about storage access first. You need to deal with different types of storages, so let’s abstract: public abstract class Folder : Enumerable<string> { public static Folder Open(...


3

Go doesn't guarantee atomicity ... so I built a simple Go interface to do that Okay, but is your implementation atomic? The only atomic operations guaranteed to be atomic in Go are through the sync/atomic package (or things like func (*Cond) Wait under sync). If you need true atomic write, use the atomic package. However, using log is usually sufficient. ...


3

You should rethink your solution in terms of regexes: #!/usr/bin/env python3 import re from os import scandir, rename, path def rename_children(parent): n_renamed = 0 re_fname = re.compile('(IMG|PANO|VID)_') for child_dir in scandir(parent): if child_dir.is_dir(): for child in scandir(child_dir): renamed = ...


3

In for instance EmbeddedFileInfo I wonder if you can sharpen the first condition in: public override bool Equals(object obj) => obj is IFileInfo file && Equals(file); to: public override bool Equals(object obj) => obj is EmbeddedFileInfo file && Equals(file); But you only compare on path so maybe not, because? I think I would ...


3

As usual there isn't much left to say about your code then I'll try to imagine to use it: I'd expect CreateFileAsync() to only create the file like File.Create(), returning a Stream to that (abstract) file. It might be even easier to use because instead of: using (var stream = new MemoryStream()) { stream.Write(...); await output.CreateFileAsync(...


3

In PhysicalFileProvider.CreateDirectory() you should place the call to Directory.Exists() inside the try..catch as well because it can throw e.g ArgumentException for "C:\test?" or a NotSupportedException for C:\:. But basically you could skip this check at all because calling Directory.CreateDirectory() will do the check itself (Directory....


3

This is a review of your 2nd review request, described as a rewrite for python3. Summary: code looks great! Much better than the older version. Many changes I suggested for the old already appear in the new. Thank you for turning mangling double __ into private single _ prefix. 0,aaa,b,c,dd (Bit Mapping) The explicit "bit mapping" remark is very ...


3

DFS (Directory and File Serialization) file format Not sure what that is. Nor is google. Recommend you offer a more specific citation, hopefully one that includes an URL. import os as _os import sys as _sys Hmmm, that's odd. Do you really need to rename them? FORMAT_DOCUMENTATION = '''\ The backwhack is very odd -- don't do it. That's what triple quotes ...


Only top voted, non community-wiki answers of a minimum length are eligible