Author: rmottola
Date: Tue May 26 16:41:51 2015
New Revision: 38563
URL: http://svn.gna.org/viewcvs/gnustep?rev=38563&view=rev
Log:
Verify and protect certain directories from file operations.
Modified:
apps/gworkspace/trunk/ChangeLog
apps/gworkspace/trunk/Operation/Operation.m
apps/gworkspace/trunk/Operation/Resources/English.lproj/Localizable.strings
Modified: apps/gworkspace/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/ChangeLog?rev=38563&r1=38562&r2=38563&view=diff
==============================================================================
--- apps/gworkspace/trunk/ChangeLog (original)
+++ apps/gworkspace/trunk/ChangeLog Tue May 26 16:41:51 2015
@@ -1,3 +1,9 @@
+2015-05-26 Riccardo Mottola <[email protected]>
+
+ * Operation/Operation.m
+ * Operation/Resources/English.lproj/Localizable.strings
+ Verify and protect certain directories from file operations.
+
2015-05-26 Riccardo Mottola <[email protected]>
* GWorkspace/FileViewer/GWViewer.m
@@ -495,7 +501,6 @@
* FSNode/FSNIconsView.h
* FSNode/FSNListView.h
Fix warnings about not implemented protocols.
-
2013-02-28 Riccardo Mottola <[email protected]>
* GWMetadata/gmds/gmds/gmds.m
Modified: apps/gworkspace/trunk/Operation/Operation.m
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Operation/Operation.m?rev=38563&r1=38562&r2=38563&view=diff
==============================================================================
--- apps/gworkspace/trunk/Operation/Operation.m (original)
+++ apps/gworkspace/trunk/Operation/Operation.m Tue May 26 16:41:51 2015
@@ -1,6 +1,6 @@
/* Operation.m
*
- * Copyright (C) 2004-2014 Free Software Foundation, Inc.
+ * Copyright (C) 2004-2015 Free Software Foundation, Inc.
*
* Author: Enrico Sersale <[email protected]>
* Date: March 2004
@@ -411,46 +411,104 @@
{
NSString *chpath = path;
BOOL valid;
+ BOOL isDir;
if (operation && ([operation isEqual: @"GWorkspaceCreateDirOperation"]
- || [operation isEqual: @"GWorkspaceCreateFileOperation"])) {
- chpath = [path stringByDeletingLastPathComponent];
- }
-
- valid = [fm fileExistsAtPath: chpath];
-
- if (valid == NO) {
+ || [operation isEqual: @"GWorkspaceCreateFileOperation"]))
+ {
+ chpath = [path stringByDeletingLastPathComponent];
+ }
+
+ valid = [fm fileExistsAtPath: chpath isDirectory:&isDir];
+
+ if (valid == NO)
+ {
/* case of broken symlink */
valid = ([fm fileAttributesAtPath: chpath traverseLink: NO] != nil);
}
- if (valid == NO) {
- NSString *err = NSLocalizedString(@"Error", @"");
- NSString *msg = NSLocalizedString(@": no such file or
directory!", @"");
- NSString *buttstr = NSLocalizedString(@"Continue", @"");
- NSMutableDictionary *notifObj = [NSMutableDictionary
dictionaryWithCapacity: 1];
- NSString *basePath = [chpath stringByDeletingLastPathComponent];
-
- NSRunAlertPanel(err, [NSString stringWithFormat: @"%@%@", chpath, msg],
buttstr, nil, nil);
-
- [notifObj setObject: NSWorkspaceDestroyOperation forKey:
@"operation"];
- [notifObj setObject: basePath forKey: @"source"];
- [notifObj setObject: basePath forKey: @"destination"];
- [notifObj setObject: [NSArray arrayWithObject: [chpath
lastPathComponent]]
- forKey: @"files"];
-
- [[NSDistributedNotificationCenter defaultCenter]
+ if (valid == NO)
+ {
+ NSString *err = NSLocalizedString(@"Error", @"");
+ NSString *msg = NSLocalizedString(@": no such file or directory!", @"");
+ NSString *buttstr = NSLocalizedString(@"Continue", @"");
+ NSMutableDictionary *notifObj = [NSMutableDictionary
dictionaryWithCapacity: 1];
+ NSString *basePath = [chpath stringByDeletingLastPathComponent];
+
+ NSRunAlertPanel(err, [NSString stringWithFormat: @"%@%@", chpath, msg],
buttstr, nil, nil);
+
+ [notifObj setObject: NSWorkspaceDestroyOperation forKey: @"operation"];
+ [notifObj setObject: basePath forKey: @"source"];
+ [notifObj setObject: basePath forKey: @"destination"];
+ [notifObj setObject: [NSArray arrayWithObject: [chpath
lastPathComponent]]
+ forKey: @"files"];
+
+ [[NSDistributedNotificationCenter defaultCenter]
postNotificationName:
@"GWFileSystemWillChangeNotification"
- object:
nil userInfo: notifObj];
-
- [[NSDistributedNotificationCenter defaultCenter]
+ object: nil userInfo: notifObj];
+
+ [[NSDistributedNotificationCenter defaultCenter]
postNotificationName:
@"GWFileSystemDidChangeNotification"
- object:
nil userInfo: notifObj];
-
- return NO;
- }
-
- return YES;
+ object: nil userInfo: notifObj];
+
+ return NO;
+ }
+ else
+ {
+ if ([operation isEqual: NSWorkspaceMoveOperation]
+ || [operation isEqual: NSWorkspaceRecycleOperation]
+ || [operation isEqual: NSWorkspaceDestroyOperation]
+ || [operation isEqual: @"GWorkspaceRecycleOutOperation"]
+ || [operation isEqual: @"GWorkspaceRenameOperation"])
+ {
+ if (isDir)
+ {
+ NSArray *specialPathArray;
+ NSString *fullPath;
+ BOOL protected = NO;
+
+ NSString *err = NSLocalizedString(@"Error", @"");
+ NSString *msg = NSLocalizedString(@": Directory Protected!",
@"");
+ NSString *buttstr = NSLocalizedString(@"Continue", @"");
+ NSMutableDictionary *notifObj = [NSMutableDictionary
dictionaryWithCapacity: 1];
+
+
+ fullPath = [path stringByExpandingTildeInPath];
+ specialPathArray =
NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSAllDomainsMask,
YES);
+ if ([specialPathArray indexOfObject:fullPath] != NSNotFound)
+ protected = YES;
+
+ if (!protected)
+ {
+ specialPathArray =
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES);
+ if ([specialPathArray indexOfObject:fullPath] != NSNotFound)
+ protected = YES;
+ }
+
+ if (!protected)
+ {
+ specialPathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
+ if ([specialPathArray indexOfObject:fullPath] != NSNotFound)
+ protected = YES;
+ }
+
+ if (!protected)
+ {
+ specialPathArray =
NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSAllDomainsMask, YES);
+ if ([specialPathArray indexOfObject:fullPath] != NSNotFound)
+ protected = YES;;
+ }
+
+ if (protected)
+ {
+ NSRunAlertPanel(err, [NSString stringWithFormat: @"%@%@",
path, msg], buttstr, nil, nil);
+ return NO;
+ }
+ }
+ }
+ }
+
+ return YES;
}
- (BOOL)ascendentOfPath:(NSString *)path
Modified:
apps/gworkspace/trunk/Operation/Resources/English.lproj/Localizable.strings
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Operation/Resources/English.lproj/Localizable.strings?rev=38563&r1=38562&r2=38563&view=diff
==============================================================================
--- apps/gworkspace/trunk/Operation/Resources/English.lproj/Localizable.strings
(original)
+++ apps/gworkspace/trunk/Operation/Resources/English.lproj/Localizable.strings
Tue May 26 16:41:51 2015
@@ -101,6 +101,8 @@
"Some items have the same name;\ndo you want to substitute them?" = "Some
items have the same name;\ndo you want to substitute them?";
"Error" = "Error";
"File Operation Error!" = "File Operation Error!";
+": no such file or directory!" = ": no such file or directory!";
+": Directory Protected!" = ": Directory Protected!";
/* ColumnIcon.m */
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs