question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`remove_path` method behaviour in `pebble`

See original GitHub issue

The remove_path method in pebble has an optional argument recursive: bool = False:

def remove_path(self, path: str, *, recursive: bool = False):

Let’s say that you need to delete a file from a container’s directory. But it’s possible that the file you trying to delete it is not yet in the directory.

If you have:

container.remove_path(path)

You will get a PathError exception since the file does not exist. This makes sense, it is behaviourally similar to rm <file>:

➜  rm pepe.txt
rm: cannot remove 'pepe.txt': No such file or directory

But there is no explicit option that behaves similar to rm -f <file> (do nothing if the files is non-existent):

➜  rm -f pepe.txt
➜

Anyway you can achieve that behaviour by using recursive=True

container.remove_path(path, recursive=True)

recursive=True behaves in 2 ways:

  • If path is a directory recursively deletes it and everything under it.
  • If the path is a file, delete the file and do nothing if the file is non-existent. Behaviourally similar to rm -rf <file|dir>

Using recursive=True when trying to delete a file and do nothing if file is non-existent (rm -f <file>) is a little bit confusing.

Shouldn’t we try to mimic the rm behaviour where we have: -r for recursive and -f for “ignore nonexistent files and arguments, never prompt”?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pengalecommented, Feb 23, 2022

I suspect that a lot of people using the lib would just pass -f, and create their own problems detecting typos.

I like the simplicity of having the library work one way, with my preferred way being to remove a path if it exists, and log a warning if it does not. (The warning gives typo makers a chance to catch their error.)

1reaction
pengalecommented, Feb 18, 2022

Thank you for filing this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

canonical/pebble: Take control of your internal ... - GitHub
The Pebble service manager. Take control of your internal daemons! Pebble helps you to orchestrate a set of local service processes as an...
Read more >
The Power of a Pebble: Exploring and Mapping Directed Graphs
Such a method for distinguishing edges is essential because otherwise it is undef ned how to choose or specify a path from one...
Read more >
pebble - Go Packages
Behaviour when a reverse positioning operation is done on an iterator opened with this option is unpredictable, though in most cases it should....
Read more >
(PDF) Abrasion behavior of graphite pebble in lifting pipe of ...
During circulation process, the pebbles are lifted pneumatically via a stainless steel lifting pipe and reinserted into the reactor. Inevitably, ...
Read more >
How to use jq to remove a path method (based on a x ...
Use del to delete fields: .paths |= del(.[] | select(. == {})) . – pmf. Nov 10 at 1:14.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found