Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion shell/plugins/panels/dropbox/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def command_output(command):
return completed.returncode, (completed.stdout + completed.stderr).strip()


# The same check `dropbox-cli running` makes, without the CLI's inverted exit code.
def daemon_running():
try:
pid = int((Path.home() / ".dropbox" / "dropbox.pid").read_text())
return "dropbox" in Path(f"/proc/{pid}/cmdline").read_text().lower()
except (OSError, ValueError):
return False


def scan_dropbox(path, limit):
total = 0
counter = 0
Expand Down Expand Up @@ -98,7 +107,11 @@ def main():

running = False
status_text = "Not installed"
if dropbox_cli:
if dropbox_cli and not authenticated:
# `dropbox-cli status` asks an unlinked daemon for a link URL, and each ask voids the one Log in opened.
running = daemon_running()
status_text = "Waiting to be linked to a Dropbox account" if running else "Stopped"
Comment on lines +110 to +113

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing folder hides actual status

If an already-linked account’s sync folder is unavailable, such as when its drive is disconnected, authenticated becomes false. This new branch then skips dropbox-cli status and shows “Waiting to be linked to a Dropbox account” for a running daemon. That misleading message makes the folder problem harder to diagnose.

Choose whether to skip the CLI from the account metadata, separately from whether the folder is available for scanning.

elif dropbox_cli:
status_exit, status_output = command_output([dropbox_cli, "status"])
status_text = status_output if status_exit == 0 and status_output else "Stopped"
lowered = status_text.lower()
Expand Down
40 changes: 40 additions & 0 deletions test/shell.d/dropbox-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,43 @@ assertEqual(
'dropbox file metadata includes relative time and folder'
)
JS

require_command jq
require_command python3

test_tmp=$(mktemp -d)
daemon_pid=""
trap '[[ -n $daemon_pid ]] && kill "$daemon_pid" 2>/dev/null; rm -rf "$test_tmp"' EXIT

mkdir -p "$test_tmp/bin" "$test_tmp/home/.dropbox"
cat >"$test_tmp/bin/dropbox-cli" <<'SH'
#!/bin/bash
echo "$*" >>"$HOME/cli.log"
echo "Up to date"
SH
chmod +x "$test_tmp/bin/dropbox-cli"

dropbox_status() {
HOME="$test_tmp/home" PATH="$test_tmp/bin:$PATH" python3 "$ROOT/shell/plugins/panels/dropbox/status.py" 25
}

# Every `dropbox-cli status` mints a new link URL while unlinked, voiding the one Log in opened.
status=$(dropbox_status)
[[ $(jq -r .running <<<"$status") == "false" && ! -e $test_tmp/home/cli.log ]] ||
fail "dropbox status reads an unlinked, stopped daemon without asking it for a link" "$status"
pass "dropbox status reads an unlinked, stopped daemon without asking it for a link"

(exec -a dropbox sleep 60) &
daemon_pid=$!
echo "$daemon_pid" >"$test_tmp/home/.dropbox/dropbox.pid"
status=$(dropbox_status)
[[ $(jq -r .running <<<"$status") == "true" && $(jq -r .authenticated <<<"$status") == "false" && ! -e $test_tmp/home/cli.log ]] ||
fail "dropbox status reads an unlinked, running daemon without asking it for a link" "$status"
pass "dropbox status reads an unlinked, running daemon without asking it for a link"

mkdir -p "$test_tmp/home/Dropbox"
jq -n --arg path "$test_tmp/home/Dropbox" '{personal: {path: $path, subscription_type: "Plus"}}' >"$test_tmp/home/.dropbox/info.json"
status=$(dropbox_status)
[[ $(jq -r .running <<<"$status") == "true" && $(jq -r .statusText <<<"$status") == "Up to date" && $(<"$test_tmp/home/cli.log") == "status" ]] ||
fail "dropbox status asks a linked daemon for its status" "$status"
pass "dropbox status asks a linked daemon for its status"