Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Windows Module: win_compact #56475

Open
wants to merge 7 commits into
base: devel
from

Conversation

Projects
None yet
5 participants
@mhunsber
Copy link
Contributor

commented May 15, 2019

SUMMARY

Adding a module for setting NTFS compression on folders/subfolders. This is shown as the Compressed flag in the file attributes, which you can get by using win_stat.

I named it win_compact so that it doesn't get confused with zip compression. The name is based on the command line tool, compact, but I use the CIM command instead, since PowerShell calls are preferred over command calls.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

win_compact

ADDITIONAL INFORMATION

if you have the folder structure:

My Folder
| file1
| file2
└ anotherfolder
  | anotherfile1
  | anotherfile2
win_compact:
  path: My Folder
  compressed: yes
  recurse: no

will compress My Folder, file1, and file2.

win_compact:
  path: My Folder
  compressed: yes
  recurse: yes

will compress My Folder, file1, file2, anotherfolder, anotherfile1, and anotherfile2

Micah Hunsberger added some commits May 15, 2019

@ansibot

This comment has been minimized.

mhunsber and others added some commits May 15, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

@mcassaniti

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

Can I suggest a name change to win_ntfs_compress? I know that makes for a rather long module name, but it is obvious for functionality. Otherwise it looks fine.

@jborean93

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

Add to potential candidates, win_file_compression. Technically the file system needs to support compression and it's not just NTFS, although I'm not aware of any other filesystems that do support this.

@chopraaa

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

Yep, it's just NTFS.

@ansibot ansibot removed the needs_triage label May 15, 2019

@mhunsber

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

I like win_file_compression. I would have went with win_ntfs_compress since I didn't add the functionality to compress single files, but I think I could add that using either CIM_LogicalFile or CIM_DataFile. Both have the (Un)CompressEx methods. The recurse option could just be ignored if path is a file

Micah Hunsberger added some commits May 16, 2019

Micah Hunsberger Micah Hunsberger
renamed to win_file_compression
added single file support
added force option to avoid traversing large directory structures
Micah Hunsberger Micah Hunsberger
Micah Hunsberger Micah Hunsberger
fixed renaming.
bench test still had win_compact as a module
@mhunsber

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

Okay, I went with win_file_compression. I also made it so you can un/compress single files if path is file.

I also changed the way it checks for whether or not it needs to perform a change. Before, it always looped through the subfolders until it found one that did not match the compressed state. Now, you can set the force parameter to false in case the folder structure is really large, and it will only check compressed state of path. I figured if there is reason to compress a folder, there are likely a lot of files/folders, and looping through them all could take a while. Also, there aren't many ways a child item would be compressed/uncompressed when the parent isn't.

@mcassaniti

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

Wouldn't it make more sense to not loop through folders based on the recurse parameter when checking what folders to apply compression to? Using force is not intuitive, especially when you've got a recurse parameter.

@mhunsber

This comment has been minimized.

Copy link
Contributor Author

commented May 20, 2019

recurse is an option for the (un)compress methods, which get called on the parent directory. The force option changes how much effort the module puts in to deciding if the (un)compress method needs to be called.
It's almost like recurse would be better named apply_recursively and force would be check_recursively.

To make the case for the extra option, if you're unsure if path is compressed, but know that it's contents are all the same state, you would use both recurse and force=no because you don't want to have to check every single subfolder and file if the parent folder does happen to be compressed. But if the parent folder isn't compressed, you want to make sure that change is applied to all children.

If you can think of a better UI, I'm for it. I know the force option is a bit unintuitive. Possibly make the recurse option a string with choices like "top directory only", "apply recursively" and "check recursively".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.