From da2a68b3eb47b9fb071def3f374258b2ce454096 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 29 Dec 2016 07:20:23 -0800 Subject: watchdog: Enable COMPILE_TEST where possible Building all watchdog drivers is all but impossible since many depend on platforms which are not enabled by test builds. Add dependency on COMPILE_TEST where possible to improve the situation. Signed-off-by: Guenter Roeck --- drivers/watchdog/Kconfig | 118 +++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'drivers/watchdog') diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 8c8b6f6e78c6..f7cb150d43d6 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -73,7 +73,7 @@ config SOFT_WATCHDOG config DA9052_WATCHDOG tristate "Dialog DA9052 Watchdog" - depends on PMIC_DA9052 + depends on PMIC_DA9052 || COMPILE_TEST select WATCHDOG_CORE help Support for the watchdog in the DA9052 PMIC. Watchdog trigger @@ -85,7 +85,7 @@ config DA9052_WATCHDOG config DA9055_WATCHDOG tristate "Dialog Semiconductor DA9055 Watchdog" - depends on MFD_DA9055 + depends on MFD_DA9055 || COMPILE_TEST select WATCHDOG_CORE help If you say yes here you get support for watchdog on the Dialog @@ -96,7 +96,7 @@ config DA9055_WATCHDOG config DA9063_WATCHDOG tristate "Dialog DA9063 Watchdog" - depends on MFD_DA9063 + depends on MFD_DA9063 || COMPILE_TEST select WATCHDOG_CORE help Support for the watchdog in the DA9063 PMIC. @@ -105,7 +105,7 @@ config DA9063_WATCHDOG config DA9062_WATCHDOG tristate "Dialog DA9062/61 Watchdog" - depends on MFD_DA9062 + depends on MFD_DA9062 || COMPILE_TEST select WATCHDOG_CORE help Support for the watchdog in the DA9062 and DA9061 PMICs. @@ -133,7 +133,7 @@ config GPIO_WATCHDOG_ARCH_INITCALL config MENF21BMC_WATCHDOG tristate "MEN 14F021P00 BMC Watchdog" - depends on MFD_MENF21BMC + depends on MFD_MENF21BMC || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the MEN 14F021P00 BMC Watchdog. @@ -168,7 +168,7 @@ config WDAT_WDT config WM831X_WATCHDOG tristate "WM831x watchdog" - depends on MFD_WM831X + depends on MFD_WM831X || COMPILE_TEST select WATCHDOG_CORE help Support for the watchdog in the WM831x AudioPlus PMICs. When @@ -209,7 +209,7 @@ config ZIIRAVE_WATCHDOG config ARM_SP805_WATCHDOG tristate "ARM SP805 Watchdog" - depends on (ARM || ARM64) && ARM_AMBA + depends on (ARM || ARM64) && (ARM_AMBA || COMPILE_TEST) select WATCHDOG_CORE help ARM Primecell SP805 Watchdog timer. This will reboot your system when @@ -237,7 +237,7 @@ config ARM_SBSA_WATCHDOG config ASM9260_WATCHDOG tristate "Alphascale ASM9260 watchdog" - depends on MACH_ASM9260 + depends on MACH_ASM9260 || COMPILE_TEST depends on OF select WATCHDOG_CORE select RESET_CONTROLLER @@ -247,14 +247,14 @@ config ASM9260_WATCHDOG config AT91RM9200_WATCHDOG tristate "AT91RM9200 watchdog" - depends on SOC_AT91RM9200 && MFD_SYSCON + depends on (SOC_AT91RM9200 && MFD_SYSCON) || COMPILE_TEST help Watchdog timer embedded into AT91RM9200 chips. This will reboot your system when the timeout is reached. config AT91SAM9X_WATCHDOG tristate "AT91SAM9X / AT91CAP9 watchdog" - depends on ARCH_AT91 + depends on ARCH_AT91 || COMPILE_TEST select WATCHDOG_CORE help Watchdog timer embedded into AT91SAM9X and AT91CAP9 chips. This will @@ -262,7 +262,7 @@ config AT91SAM9X_WATCHDOG config SAMA5D4_WATCHDOG tristate "Atmel SAMA5D4 Watchdog Timer" - depends on ARCH_AT91 + depends on ARCH_AT91 || COMPILE_TEST select WATCHDOG_CORE help Atmel SAMA5D4 watchdog timer is embedded into SAMA5D4 chips. @@ -293,7 +293,7 @@ config 21285_WATCHDOG config 977_WATCHDOG tristate "NetWinder WB83C977 watchdog" - depends on FOOTBRIDGE && ARCH_NETWINDER + depends on (FOOTBRIDGE && ARCH_NETWINDER) || (ARM && COMPILE_TEST) help Say Y here to include support for the WB977 watchdog included in NetWinder machines. Alternatively say M to compile the driver as @@ -333,7 +333,7 @@ config HAVE_S3C2410_WATCHDOG config S3C2410_WATCHDOG tristate "S3C2410 Watchdog" - depends on HAVE_S3C2410_WATCHDOG + depends on HAVE_S3C2410_WATCHDOG || COMPILE_TEST select WATCHDOG_CORE select MFD_SYSCON if ARCH_EXYNOS5 help @@ -372,7 +372,7 @@ config DW_WATCHDOG config EP93XX_WATCHDOG tristate "EP93xx Watchdog" - depends on ARCH_EP93XX + depends on ARCH_EP93XX || COMPILE_TEST select WATCHDOG_CORE help Say Y here if to include support for the watchdog timer @@ -383,7 +383,7 @@ config EP93XX_WATCHDOG config OMAP_WATCHDOG tristate "OMAP Watchdog" - depends on ARCH_OMAP16XX || ARCH_OMAP2PLUS + depends on ARCH_OMAP16XX || ARCH_OMAP2PLUS || COMPILE_TEST select WATCHDOG_CORE help Support for TI OMAP1610/OMAP1710/OMAP2420/OMAP3430/OMAP4430 watchdog. Say 'Y' @@ -419,7 +419,7 @@ config IOP_WATCHDOG config DAVINCI_WATCHDOG tristate "DaVinci watchdog" - depends on ARCH_DAVINCI || ARCH_KEYSTONE + depends on ARCH_DAVINCI || ARCH_KEYSTONE || COMPILE_TEST select WATCHDOG_CORE help Say Y here if to include support for the watchdog timer @@ -432,7 +432,7 @@ config DAVINCI_WATCHDOG config ORION_WATCHDOG tristate "Orion watchdog" - depends on ARCH_ORION5X || ARCH_DOVE || MACH_DOVE || ARCH_MVEBU + depends on ARCH_ORION5X || ARCH_DOVE || MACH_DOVE || ARCH_MVEBU || COMPILE_TEST depends on ARM select WATCHDOG_CORE help @@ -443,7 +443,7 @@ config ORION_WATCHDOG config RN5T618_WATCHDOG tristate "Ricoh RN5T618 watchdog" - depends on MFD_RN5T618 + depends on MFD_RN5T618 || COMPILE_TEST select WATCHDOG_CORE help If you say yes here you get support for watchdog on the Ricoh @@ -454,7 +454,7 @@ config RN5T618_WATCHDOG config SUNXI_WATCHDOG tristate "Allwinner SoCs watchdog support" - depends on ARCH_SUNXI + depends on ARCH_SUNXI || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer @@ -464,7 +464,7 @@ config SUNXI_WATCHDOG config COH901327_WATCHDOG bool "ST-Ericsson COH 901 327 watchdog" - depends on ARCH_U300 + depends on ARCH_U300 || (ARM && COMPILE_TEST) default y if MACH_U300 select WATCHDOG_CORE help @@ -483,7 +483,7 @@ config TWL4030_WATCHDOG config STMP3XXX_RTC_WATCHDOG tristate "Freescale STMP3XXX & i.MX23/28 watchdog" - depends on RTC_DRV_STMP + depends on RTC_DRV_STMP || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer inside @@ -493,7 +493,7 @@ config STMP3XXX_RTC_WATCHDOG config NUC900_WATCHDOG tristate "Nuvoton NUC900 watchdog" - depends on ARCH_W90X900 + depends on ARCH_W90X900 || COMPILE_TEST help Say Y here if to include support for the watchdog timer for the Nuvoton NUC900 series SoCs. @@ -513,7 +513,7 @@ config TS4800_WATCHDOG config TS72XX_WATCHDOG tristate "TS-72XX SBC Watchdog" - depends on MACH_TS72XX + depends on MACH_TS72XX || COMPILE_TEST help Technologic Systems TS-7200, TS-7250 and TS-7260 boards have watchdog timer implemented in a external CPLD chip. Say Y here @@ -531,7 +531,7 @@ config MAX63XX_WATCHDOG config MAX77620_WATCHDOG tristate "Maxim Max77620 Watchdog Timer" - depends on MFD_MAX77620 + depends on MFD_MAX77620 || COMPILE_TEST help This is the driver for the Max77620 watchdog timer. Say 'Y' here to enable the watchdog timer support for @@ -540,7 +540,7 @@ config MAX77620_WATCHDOG config IMX2_WDT tristate "IMX2+ Watchdog" - depends on ARCH_MXC || ARCH_LAYERSCAPE + depends on ARCH_MXC || ARCH_LAYERSCAPE || COMPILE_TEST select REGMAP_MMIO select WATCHDOG_CORE help @@ -554,7 +554,7 @@ config IMX2_WDT config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" - depends on MFD_DB8500_PRCMU + depends on MFD_DB8500_PRCMU || (ARM && COMPILE_TEST) select WATCHDOG_CORE default y help @@ -566,7 +566,7 @@ config UX500_WATCHDOG config RETU_WATCHDOG tristate "Retu watchdog" - depends on MFD_RETU + depends on MFD_RETU || COMPILE_TEST select WATCHDOG_CORE help Retu watchdog driver for Nokia Internet Tablets (770, N800, @@ -578,7 +578,7 @@ config RETU_WATCHDOG config MOXART_WDT tristate "MOXART watchdog" - depends on ARCH_MOXART + depends on ARCH_MOXART || COMPILE_TEST help Say Y here to include Watchdog timer support for the watchdog existing on the MOXA ART SoC series platforms. @@ -588,7 +588,7 @@ config MOXART_WDT config SIRFSOC_WATCHDOG tristate "SiRFSOC watchdog" - depends on ARCH_SIRF + depends on ARCH_SIRF || COMPILE_TEST select WATCHDOG_CORE default y help @@ -597,7 +597,7 @@ config SIRFSOC_WATCHDOG config ST_LPC_WATCHDOG tristate "STMicroelectronics LPC Watchdog" - depends on ARCH_STI + depends on ARCH_STI || COMPILE_TEST depends on OF select WATCHDOG_CORE help @@ -621,7 +621,7 @@ config TEGRA_WATCHDOG config QCOM_WDT tristate "QCOM watchdog" depends on HAS_IOMEM - depends on ARCH_QCOM + depends on ARCH_QCOM || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include Watchdog timer support for the watchdog found @@ -633,7 +633,7 @@ config QCOM_WDT config MESON_GXBB_WATCHDOG tristate "Amlogic Meson GXBB SoCs watchdog support" - depends on ARCH_MESON + depends on ARCH_MESON || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer @@ -643,7 +643,7 @@ config MESON_GXBB_WATCHDOG config MESON_WATCHDOG tristate "Amlogic Meson SoCs watchdog support" - depends on ARCH_MESON + depends on ARCH_MESON || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer @@ -653,7 +653,7 @@ config MESON_WATCHDOG config MEDIATEK_WATCHDOG tristate "Mediatek SoCs watchdog support" - depends on ARCH_MEDIATEK + depends on ARCH_MEDIATEK || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer @@ -663,7 +663,7 @@ config MEDIATEK_WATCHDOG config DIGICOLOR_WATCHDOG tristate "Conexant Digicolor SoCs watchdog support" - depends on ARCH_DIGICOLOR + depends on ARCH_DIGICOLOR || COMPILE_TEST select WATCHDOG_CORE help Say Y here to include support for the watchdog timer @@ -685,7 +685,7 @@ config LPC18XX_WATCHDOG config ATLAS7_WATCHDOG tristate "CSRatlas7 watchdog" - depends on ARCH_ATLAS7 + depends on ARCH_ATLAS7 || COMPILE_TEST help Say Y here to include Watchdog timer support for the watchdog existing on the CSRatlas7 series platforms. @@ -718,7 +718,7 @@ config ASPEED_WATCHDOG config AT32AP700X_WDT tristate "AT32AP700x watchdog" - depends on CPU_AT32AP700X + depends on CPU_AT32AP700X || COMPILE_TEST help Watchdog timer embedded into AT32AP700x devices. This will reboot your system when the timeout is reached. @@ -822,7 +822,7 @@ config SP5100_TCO config GEODE_WDT tristate "AMD Geode CS5535/CS5536 Watchdog" - depends on CS5535_MFGPT + depends on CS5535_MFGPT || (X86 && COMPILE_TEST) help This driver enables a watchdog capability built into the CS5535/CS5536 companion chips for the AMD Geode GX and LX @@ -835,7 +835,7 @@ config GEODE_WDT config SC520_WDT tristate "AMD Elan SC520 processor Watchdog" - depends on MELAN + depends on MELAN || COMPILE_TEST help This is the driver for the hardware watchdog built in to the AMD "Elan" SC520 microcomputer commonly used in embedded systems. @@ -1034,7 +1034,7 @@ config HP_WATCHDOG config KEMPLD_WDT tristate "Kontron COM Watchdog Timer" - depends on MFD_KEMPLD + depends on MFD_KEMPLD || COMPILE_TEST select WATCHDOG_CORE help Support for the PLD watchdog on some Kontron ETX and COMexpress @@ -1108,7 +1108,7 @@ config NV_TCO config RDC321X_WDT tristate "RDC R-321x SoC watchdog" - depends on X86_RDC321X + depends on X86_RDC321X || COMPILE_TEST help This is the driver for the built in hardware watchdog in the RDC R-321x SoC. @@ -1353,14 +1353,14 @@ config M54xx_WATCHDOG config ATH79_WDT tristate "Atheros AR71XX/AR724X/AR913X hardware watchdog" - depends on ATH79 + depends on ATH79 || (ARM && COMPILE_TEST) help Hardware driver for the built-in watchdog timer on the Atheros AR71XX/AR724X/AR913X SoCs. config BCM47XX_WDT tristate "Broadcom BCM47xx Watchdog Timer" - depends on BCM47XX || ARCH_BCM_5301X + depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST select WATCHDOG_CORE help Hardware driver for the Broadcom BCM47xx Watchdog Timer. @@ -1377,7 +1377,7 @@ config RC32434_WDT config INDYDOG tristate "Indy/I2 Hardware Watchdog" - depends on SGI_HAS_INDYDOG + depends on SGI_HAS_INDYDOG || (MIPS && COMPILE_TEST) help Hardware driver for the Indy's/I2's watchdog. This is a watchdog timer that will reboot the machine after a 60 second @@ -1393,7 +1393,7 @@ config JZ4740_WDT config WDT_MTX1 tristate "MTX-1 Hardware Watchdog" - depends on MIPS_MTX1 + depends on MIPS_MTX1 || (MIPS && COMPILE_TEST) help Hardware driver for the MTX-1 boards. This is a watchdog timer that will reboot the machine after a 100 seconds timer expired. @@ -1410,7 +1410,7 @@ config PNX833X_WDT config SIBYTE_WDOG tristate "Sibyte SoC hardware watchdog" - depends on CPU_SB1 + depends on CPU_SB1 || (MIPS && COMPILE_TEST) help Watchdog driver for the built in watchdog hardware in Sibyte SoC processors. There are apparently two watchdog timers @@ -1423,13 +1423,13 @@ config SIBYTE_WDOG config AR7_WDT tristate "TI AR7 Watchdog Timer" - depends on AR7 + depends on AR7 || (MIPS && COMPILE_TEST) help Hardware driver for the TI AR7 Watchdog Timer. config TXX9_WDT tristate "Toshiba TXx9 Watchdog Timer" - depends on CPU_TX39XX || CPU_TX49XX + depends on CPU_TX39XX || CPU_TX49XX || (MIPS && COMPILE_TEST) select WATCHDOG_CORE help Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs. @@ -1465,7 +1465,7 @@ config BCM63XX_WDT config BCM2835_WDT tristate "Broadcom BCM2835 hardware watchdog" - depends on ARCH_BCM2835 + depends on ARCH_BCM2835 || COMPILE_TEST select WATCHDOG_CORE help Watchdog driver for the built in watchdog hardware in Broadcom @@ -1476,7 +1476,7 @@ config BCM2835_WDT config BCM_KONA_WDT tristate "BCM Kona Watchdog" - depends on ARCH_BCM_MOBILE + depends on ARCH_BCM_MOBILE || COMPILE_TEST select WATCHDOG_CORE help Support for the watchdog timer on the following Broadcom BCM281xx @@ -1488,7 +1488,7 @@ config BCM_KONA_WDT config BCM_KONA_WDT_DEBUG bool "DEBUGFS support for BCM Kona Watchdog" - depends on BCM_KONA_WDT + depends on BCM_KONA_WDT || COMPILE_TEST help If enabled, adds /sys/kernel/debug/bcm_kona_wdt/info which provides access to the driver's internal data structures as well as watchdog @@ -1549,7 +1549,7 @@ config MT7621_WDT config PIC32_WDT tristate "Microchip PIC32 hardware watchdog" select WATCHDOG_CORE - depends on MACH_PIC32 + depends on MACH_PIC32 || (MIPS && COMPILE_TEST) help Watchdog driver for the built in watchdog hardware in a PIC32. @@ -1562,7 +1562,7 @@ config PIC32_WDT config PIC32_DMT tristate "Microchip PIC32 Deadman Timer" select WATCHDOG_CORE - depends on MACH_PIC32 + depends on MACH_PIC32 || (MIPS && COMPILE_TEST) help Watchdog driver for PIC32 instruction fetch counting timer. This specific timer is typically be used in misson critical and safety critical @@ -1584,7 +1584,7 @@ config GEF_WDT config MPC5200_WDT bool "MPC52xx Watchdog Timer" - depends on PPC_MPC52xx + depends on PPC_MPC52xx || COMPILE_TEST help Use General Purpose Timer (GPT) 0 on the MPC5200 as Watchdog. @@ -1603,11 +1603,11 @@ config 8xxx_WDT config MV64X60_WDT tristate "MV64X60 (Marvell Discovery) Watchdog Timer" - depends on MV64X60 + depends on MV64X60 || COMPILE_TEST config PIKA_WDT tristate "PIKA FPGA Watchdog" - depends on WARP + depends on WARP || (PPC64 && COMPILE_TEST) default y help This enables the watchdog in the PIKA FPGA. Currently used on @@ -1657,7 +1657,7 @@ config MEN_A21_WDT config WATCHDOG_RTAS tristate "RTAS watchdog" - depends on PPC_RTAS + depends on PPC_RTAS || (PPC64 && COMPILE_TEST) help This driver adds watchdog support for the RTAS watchdog. @@ -1685,7 +1685,7 @@ config DIAG288_WATCHDOG config SH_WDT tristate "SuperH Watchdog" - depends on SUPERH && (CPU_SH3 || CPU_SH4) + depends on SUPERH && (CPU_SH3 || CPU_SH4 || COMPILE_TEST) select WATCHDOG_CORE help This driver adds watchdog support for the integrated watchdog in the @@ -1752,7 +1752,7 @@ config XEN_WDT config UML_WATCHDOG tristate "UML watchdog" - depends on UML + depends on UML || COMPILE_TEST # # ISA-based Watchdog Cards -- cgit v1.2.3 a> 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
/* trash.c -- functions to manage the trash system */

/*
 * This file is part of CliFM
 * 
 * Copyright (C) 2016-2024, L. Abramovich <leo.clifm@outlook.com>
 * All rights reserved.

 * CliFM is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * CliFM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
*/

#ifndef _NO_TRASH

#include "helpers.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h> /* access, unlinkat */
/* <time.h>, required by time(2) and localtime_r(2), is included by "aux.h" */

#if defined(MAC_OS_X_RENAMEAT_SYS_STDIO_H)
# include <sys/stdio.h> /* renameat(2) */
#endif /* MAC_OS_X_RENAMEAT_SYS_STDIO_H */

#include "aux.h"        /* gen_date_suffix, count_dir, open_fwrite, open_fread,
xatoi, url_encode, xnmalloc, print_file_name */
#include "checks.h"     /* is_file_in_cwd, is_number */
#include "colors.h"     /* colors_list */
#include "listing.h"    /* reload_dirlist */
#include "misc.h"       /* xerror, print_reload_msg */
#include "navigation.h" /* xchdir */
#include "properties.h" /* get_color_size */
#include "readline.h"   /* rl_no_hist, rl_get_y_or_n */
#include "sort.h"       /* skip_files, xalphasort, alphasort_insensitive */
#include "spawn.h"      /* launch_execv */
#include "xdu.h"        /* dir_size */

/* Return the amount of currently trashed files. */
static size_t
count_trashed_files(void)
{
	size_t n = 0;
	if (trash_ok == 1 && trash_files_dir != NULL) {
		filesn_t ret = count_dir(trash_files_dir, NO_CPOP);
		if (ret <= 2)
			n = 0;
		else
			n = (size_t)ret - 2;
	}

	return n;
}

/* Confirm the removal of N files from the trash can.
 * Return 1 if yes or 0 if not. */
static int
confirm_removal(const size_t n)
{
	if (conf.rm_force == 1)
		return 1; /* Yes */

	char msg[256]; /* Big enough, in case of translations. */
	snprintf(msg, sizeof(msg), _("Remove %zu file(s)? [y/n] "), n);

	return rl_get_y_or_n(msg);
}

/* We have removed N files from the trash can. Print the results. */
static void
print_removal_result(const size_t n)
{
	if (conf.autols == 1)
		reload_dirlist();

	const size_t cur = (n <= trash_n ? (trash_n - n) : 0);

	if (cur == 0) {
		print_reload_msg(_("Trash can emptied: %zu file(s) removed\n"), n);
	} else {
		print_reload_msg(_("%zu file(s) removed from the trash can\n"), n);
		print_reload_msg(_("%zu total trashed file(s)\n"), cur);
	}
}

/* Remove the file named NAME and the corresponding .trashinfo file from
 * the trash can.
 * Return 0 on success or >0 on error. */
static int
remove_file_from_trash(const char *name)
{
	size_t len = strlen(name) + 11;
	char *info_file = xnmalloc(len, sizeof(char));
	snprintf(info_file, len, "%s.trashinfo", name);

	len = strlen(trash_files_dir) + strlen(name)