Skip to content

Commit

Permalink
Check write permission wipe path
Browse files Browse the repository at this point in the history
  • Loading branch information
Erriez committed Mar 5, 2023
1 parent 6deb3c9 commit 7809e45
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/shred.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def shred_menu_activate_cb(self, menu, data):
flags=0,
message_type=Gtk.MessageType.QUESTION,
buttons=Gtk.ButtonsType.YES_NO,
title="Caja shred",
text="Are you sure you want to shred selected files?",
)
dialog.format_secondary_text("WARNING: This cannot be undone!")
Expand All @@ -58,6 +59,20 @@ def wipe_freepsace_menu_activate_cb(self, menu, data):
wipe_cmd = data['cmd'].replace('of=', 'of={}/'.format(wipe_path))
clean_cmd = 'rm {}/{}'.format(wipe_path, self.WIPE_FILENAME)

# Check if wipe path is writable
if not os.access(wipe_path, os.W_OK):
dialog = Gtk.MessageDialog(
parent=None,
flags=0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
title="Caja wipe freespace",
text="Error: Directory is not writable",
)
response = dialog.run()
dialog.destroy()
return

# Start wipe freespace command
print('Running: {}'.format(wipe_cmd))
try:
Expand All @@ -77,6 +92,7 @@ def wipe_freepsace_menu_activate_cb(self, menu, data):
flags=0,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
title="Caja wipe freespace",
text="Wipe freespace completed!",
)
response = dialog.run()
Expand Down

0 comments on commit 7809e45

Please sign in to comment.