Skip to content

Commit

Permalink
ignore trash and cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Poikilos committed Dec 21, 2017
1 parent ed931bc commit 418da8d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 45 deletions.
103 changes: 59 additions & 44 deletions DFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,55 +169,70 @@ public bool get_is_match(DirectoryInfo this_info) {
} else Console.Error.WriteLine ("get_is_match(DirectoryInfo):null");
return result;
}
public static bool ContainsI(ArrayList haystack, string needle) {
bool result = false;
if (haystack!=null) {
needle = needle.ToLower();
foreach (string s in haystack) {
if (s.ToLower()==needle) {
result = true;
break;
}
}
}
return result;
}
private bool get_is_folder_searchable(DirectoryInfo this_di, bool device_allow_enable)
{
bool result = false;
FileAttributes attributes = FileAttributes.Normal;
if (this_di != null) {
try {
if (
!this_di.Name.EndsWith (":")
&&!this_di.Name.StartsWith("Singleton")
&& !this_di.Name.EndsWith ("Socket")
) {
Console.WriteLine ("get_is_folder_searchable:" + this_di.Name);
//if (!follow_folder_symlinks_enable
// || !follow_system_folders_enable
// || !follow_hidden_folders_enable
// || !follow_temporary_folders_enable
// )
attributes = File.GetAttributes(this_di.FullName);
if (options.recursive_enable
&& (options.follow_folder_symlinks_enable || !((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint))
&& ((options.follow_system_folders_enable || device_allow_enable) || !((attributes & FileAttributes.System) == FileAttributes.System))
&& (options.follow_hidden_folders_enable || !((attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
&& (options.follow_temporary_folders_enable || !((attributes & FileAttributes.Temporary) == FileAttributes.Temporary))
&& (device_allow_enable || !((attributes & FileAttributes.Device) == FileAttributes.Device))
&& (options.follow_dot_folders_enable || !this_di.Name.StartsWith ("."))
&& !((attributes & FileAttributes.Offline) == FileAttributes.Offline)
) {
result = true;
if (options.never_use_names==null || !ContainsI(options.never_use_names, this_di.Name)) {
FileAttributes attributes = FileAttributes.Normal;
if (this_di != null) {
try {
if (
!this_di.Name.EndsWith (":")
&&!this_di.Name.StartsWith("Singleton")
&& !this_di.Name.EndsWith ("Socket")
) {
Console.WriteLine ("get_is_folder_searchable:" + this_di.Name);
//if (!follow_folder_symlinks_enable
// || !follow_system_folders_enable
// || !follow_hidden_folders_enable
// || !follow_temporary_folders_enable
// )
attributes = File.GetAttributes(this_di.FullName);
if (options.recursive_enable
&& (options.follow_folder_symlinks_enable || !((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint))
&& ((options.follow_system_folders_enable || device_allow_enable) || !((attributes & FileAttributes.System) == FileAttributes.System))
&& (options.follow_hidden_folders_enable || !((attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
&& (options.follow_temporary_folders_enable || !((attributes & FileAttributes.Temporary) == FileAttributes.Temporary))
&& (device_allow_enable || !((attributes & FileAttributes.Device) == FileAttributes.Device))
&& (options.follow_dot_folders_enable || !this_di.Name.StartsWith ("."))
&& !((attributes & FileAttributes.Offline) == FileAttributes.Offline)
) {
result = true;
}
else {
if ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) Console.Error.WriteLine(" not searchable since ReparsePoint: "+this_di.FullName);
else if ((attributes & FileAttributes.System) == FileAttributes.System) Console.Error.WriteLine(" not searchable since System: "+this_di.FullName);
else if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) Console.Error.WriteLine(" not searchable since Hidden: "+this_di.FullName);
else if ((attributes & FileAttributes.Temporary) == FileAttributes.Temporary) Console.Error.WriteLine(" not searchable since Temporary: "+this_di.FullName);
else if ((attributes & FileAttributes.Offline) == FileAttributes.Offline) Console.Error.WriteLine(" not searchable since Offline: "+this_di.FullName);
else if ((attributes & FileAttributes.Device) == FileAttributes.Device) Console.Error.WriteLine(" not searchable since Device: "+this_di.FullName);
else Console.Error.WriteLine(" not searchable for unknown reason (this should never happen)");
}
}
else {
if ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) Console.Error.WriteLine(" not searchable since ReparsePoint: "+this_di.FullName);
else if ((attributes & FileAttributes.System) == FileAttributes.System) Console.Error.WriteLine(" not searchable since System: "+this_di.FullName);
else if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) Console.Error.WriteLine(" not searchable since Hidden: "+this_di.FullName);
else if ((attributes & FileAttributes.Temporary) == FileAttributes.Temporary) Console.Error.WriteLine(" not searchable since Temporary: "+this_di.FullName);
else if ((attributes & FileAttributes.Offline) == FileAttributes.Offline) Console.Error.WriteLine(" not searchable since Offline: "+this_di.FullName);
else if ((attributes & FileAttributes.Device) == FileAttributes.Device) Console.Error.WriteLine(" not searchable since Device: "+this_di.FullName);
else Console.Error.WriteLine(" not searchable for unknown reason (this should never happen)");
else {
Console.Error.WriteLine("Skipped non-folderlike name: " + this_di.Name);
}
}
else {
Console.Error.WriteLine("Skipped non-folderlike name: " + this_di.Name);
}
}
catch {
Console.Error.WriteLine("Could not finish get_is_folder_searchable " + this_di.FullName);
//ignore since probably a privelege issue or non-folder specified
}
}
else Console.Error.WriteLine("get_is_folder_searchable:null");
}
catch {
Console.Error.WriteLine("Could not finish get_is_folder_searchable " + this_di.FullName);
//ignore since probably a privelege issue or non-folder specified
}
}
else Console.Error.WriteLine("get_is_folder_searchable:null");
}
return result;
}
/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions DFFSearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DFFSearchOptions
public bool modified_start_time_enable = false;
public bool modified_endbefore_time_enable = false;
public ArrayList start_directoryinfos = null;
public ArrayList never_use_names = null;
public string name_string = null;
public string content_string = null;
public bool recursive_enable = true;
Expand All @@ -54,6 +55,9 @@ public class DFFSearchOptions
public DFFSearchOptions()
{
start_directoryinfos = new ArrayList();
never_use_names = new ArrayList();
never_use_names.Add(".cache");
never_use_names.Add("Trash");
}

public void DumpToDebug() {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The goal of this project is to create the most satisfying search program in the

## Changes
(! = important)
* (2017-12-21) By default (see never_use_names, which can be null, in DFFSearchOptions) never recurse into folders called Trash or .cache
* (2017-12-19) Released 3.1.1
* (2017-12-19) do not check for searchability (`get_is_folder_searchable`) if folder is specified by user (`depth == 0`)
* (2017-12-19) improved install script (check for ./bin/Release in case binary there instead of just in ./bin)
Expand Down
2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fi
#else
chmod +x "$dest_bin_path"
echo "$install_description finished successfully."
echo "Run using command below (or make shortcut in your window manager to):"
echo "Run using shortcut or command below (made shortcut in $applications_root):"
echo " $project_unix_name"
#fi
echo
Expand Down

0 comments on commit 418da8d

Please sign in to comment.