Skip to content

Commit

Permalink
Added documenation on using chmod. Added Windodws support by making t…
Browse files Browse the repository at this point in the history
…he call a noop.
  • Loading branch information
bsutton committed Jun 16, 2021
1 parent 2a82392 commit ede1b7b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/src/functions/chmod.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import '../../dcli.dart';
import '../util/dcli_exception.dart';
import '../util/stack_trace_impl.dart';
Expand All @@ -9,6 +11,29 @@ import 'dcli_function.dart';
/// [permission] is the standard bit map used by chmod e.g. 777
/// [path] is the path to the file that we are changing the
/// permissions of.
///
/// The the [permission] digits are intrepeted as owner, group, other.
/// So:
/// 641
/// owner - 6
/// group - 4
/// other - 1
///
/// Each digit is the sum of the permissions:
/// 4 - allow read
/// 2 - allow write
/// 1 - all execute
///
/// So 6 is 4 + 2 is read and write.
///
/// To set give the owner execution privileges use:
/// ```dart
/// chmod(100, '/path/to/exe');
/// ```
/// If [path] doesn't exist a ChModException] is thrown.
///
/// On Windows a call to this method is a noop.
///
void chmod(int permission, String path) => _ChMod()._chmod(permission, path);

/// Implementatio for [chmod] function.
Expand All @@ -19,7 +44,9 @@ class _ChMod extends DCliFunction {
if (!exists(path)) {
throw ChModException('The file at ${truepath(path)} does not exists');
}
'chmod $permission "$path"'.run;
if (!Platform.isWindows) {
'chmod $permission "$path"'.run;
}
}

// String chmod({int user, int group, int other, this.path}) {}
Expand Down

0 comments on commit ede1b7b

Please sign in to comment.