Index: src/chmod.c =================================================================== RCS file: /cvsroot/coreutils/coreutils/src/chmod.c,v retrieving revision 1.113 diff -u -r1.113 chmod.c --- src/chmod.c 29 Jun 2005 16:27:37 -0000 1.113 +++ src/chmod.c 17 Jul 2005 11:01:33 -0000 @@ -235,6 +235,21 @@ ok = false; } } + else + { +#if HAVE_LCHMOD + if (lchmod (file, new_mode) == 0) + chmod_succeeded = true; + else + { + if (! force_silent) + error (0, errno, _("changing permissions of symbolic link %s"), + quote (file_full_name)); + ok = false; + } +#endif + } + } if (verbosity != V_off) @@ -343,6 +358,9 @@ -v, --verbose output a diagnostic for every file processed\n\ --reference=RFILE use RFILE's mode instead of MODE values\n\ -R, --recursive change files and directories recursively\n\ + -P with -R, do not follow symblic links (default)\n\ + -L with -R, follow all symbolic links\n\ + -H with -R, follow links only for named files\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); @@ -368,7 +386,8 @@ bool preserve_root = false; char const *reference_file = NULL; int c; - + int symlink_options = FTS_PHYSICAL; + initialize_main (&argc, &argv); program_name = argv[0]; setlocale (LC_ALL, ""); @@ -378,9 +397,9 @@ atexit (close_stdout); recurse = force_silent = diagnose_surprises = false; - + while ((c = getopt_long (argc, argv, - "Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::", + "HLPRcfvr::w::x::X::s::t::u::g::o::a::,::+::=::", long_options, NULL)) != -1) { @@ -434,6 +453,15 @@ case REFERENCE_FILE_OPTION: reference_file = optarg; break; + case 'H': + symlink_options = FTS_COMFOLLOW; + break; + case 'L': + symlink_options = FTS_LOGICAL; + break; + case 'P': /* default if -R, ignored otherwise */ + symlink_options = FTS_PHYSICAL; + break; case 'R': recurse = true; break; @@ -507,7 +535,11 @@ root_dev_ino = NULL; } - ok = process_files (argv + optind, FTS_COMFOLLOW); + /* Options -H, -L and -P are ignored in the absence of -R. */ + if (!recurse) + symlink_options = FTS_COMFOLLOW; + + ok = process_files (argv + optind, symlink_options); exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); }