【问题标题】:The permissions of a file won't change to the ones I want文件的权限不会更改为我想要的权限
【发布时间】:2019-02-04 01:22:13
【问题描述】:

我的 Mojolicious 应用中有这个:

  my $content = get_content();
  open my $fl, '>', $my_file_full_path
      or die $!;

  print $fl $content;
  close $fl;


  # change owner to my_user:my_user
  my $uid = getpwnam "my_user";
  my $gid = getgrnam "my_user";
  chown $uid, $gid, $my_file_full_path;

  # change permissions
  chmod 0777, $my_file_full_path;

但是,最终新建文件的权限仍然是rwxr-xr-x,而不是777

如何解决这个问题?为什么会这样?

【问题讨论】:

  • 您是否检查过这些 chown 和 chmod 调用是否成功?
  • 是运行此脚本的用户,也是该文件的所有者吗?
  • chown 将失败,除非由 root 运行
  • @the.Legend 我知道
  • @GerhardBarnard 它是根

标签: linux perl file permissions mojolicious


【解决方案1】:

查看$! 变量以查看系统调用的错误:

chmod 0777, $my_file_full_path 
      or warn "Could not chmod for $my_file_full_path: $!";

一旦您告诉我们答案,我们就可以看到有关修复它的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 2012-04-27
    • 2020-08-12
    • 2016-01-20
    • 2021-08-26
    相关资源
    最近更新 更多