Skip to content

Commit

Permalink
mdns: fix test case issue and clean temp file after download
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Jan 6, 2024
1 parent 7519005 commit a1dd9ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions package/openwrt/files/etc/init.d/smartdns
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if [ ! -d "/run" ]; then
SERVICE_PID_FILE="/var/run/smartdns.pid"
fi

SMARTDNS_DOWNLOAD_TMP_DIR="/tmp/smartdns-download"
SMARTDNS_DEFAULT_FORWARDING_FILE="/etc/smartdns/domain-forwarding.list"
SMARTDNS_DEFAULT_DOMAIN_BLOCK_FILE="/etc/smartdns/domain-block.list"
SMARTDNS_CONF_DIR="/etc/smartdns"
Expand Down Expand Up @@ -850,21 +851,21 @@ download_file() {
export https_proxy="$proxy"
}
}
wget --timeout 120 -q -O "/tmp/$name" "$url"
wget --timeout 120 -q -O "$SMARTDNS_DOWNLOAD_TMP_DIR/$name" "$url"
if [ $? -ne 0 ]; then
echo "download file $name failed"
return 1
fi

echo "download file $name success"
if [ "$filetype" = "list" ]; then
mv "/tmp/$name" "$SMARTDNS_DOMAIN_LIST_DOWNLOAD_DIR/$name"
mv "$SMARTDNS_DOWNLOAD_TMP_DIR/$name" "$SMARTDNS_DOMAIN_LIST_DOWNLOAD_DIR/$name"
elif [ "$filetype" = "config" ]; then
mv "/tmp/$name" "$SMARTDNS_CONF_DOWNLOAD_DIR/$name"
mv "$SMARTDNS_DOWNLOAD_TMP_DIR/$name" "$SMARTDNS_CONF_DOWNLOAD_DIR/$name"
elif [ "$filetype" = "ip-set" ]; then
mv "/tmp/$name" "$SMARTDNS_IP_SET_DOWNLOAD_DIR/$name"
mv "$SMARTDNS_DOWNLOAD_TMP_DIR/$name" "$SMARTDNS_IP_SET_DOWNLOAD_DIR/$name"
else
mv "/tmp/$name" "$SMARTDNS_DOWNLOAD_DIR/$name"
mv "$SMARTDNS_DOWNLOAD_TMP_DIR/$name" "$SMARTDNS_DOWNLOAD_DIR/$name"
fi
}

Expand Down Expand Up @@ -903,7 +904,9 @@ check_and_add_entry() {

updatefiles() {
config_load "smartdns"
[ ! -d "$SMARTDNS_DOWNLOAD_TMP_DIR" ] && mkdir -p "$SMARTDNS_DOWNLOAD_TMP_DIR"
config_foreach download_file "download-file"
rm -rf "$SMARTDNS_DOWNLOAD_TMP_DIR" >/dev/null 2>&1
reload_service
}

Expand Down
4 changes: 2 additions & 2 deletions test/cases/test-mdns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ dualstack-ip-selection no
mdns-lookup yes
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("-x 192.168.1.1", 60053));
ASSERT_TRUE(client.Query("-x 127.0.0.9", 60053));
std::cout << client.GetResult() << std::endl;
ASSERT_EQ(client.GetAnswerNum(), 1);
EXPECT_EQ(client.GetStatus(), "NOERROR");
EXPECT_EQ(client.GetAnswer()[0].GetName(), "1.1.168.192.in-addr.arpa");
EXPECT_EQ(client.GetAnswer()[0].GetName(), "9.0.0.127.in-addr.arpa");
EXPECT_EQ(client.GetAnswer()[0].GetData(), "host.local.");
}

0 comments on commit a1dd9ab

Please sign in to comment.