summaryrefslogtreecommitdiffstats
path: root/base/files/file_path.h
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-09 17:06:52 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-09 17:06:52 +0000
commit18cbba0aedd9d569b27be8adbd2836c839ae9897 (patch)
tree0e295b353cc6cf49ccbe99f570ef4e26da2d6399 /base/files/file_path.h
parentcee59fe89f9bdb4f5f3ea676bb01538668a3ebd8 (diff)
downloadchromium_src-18cbba0aedd9d569b27be8adbd2836c839ae9897.zip
chromium_src-18cbba0aedd9d569b27be8adbd2836c839ae9897.tar.gz
chromium_src-18cbba0aedd9d569b27be8adbd2836c839ae9897.tar.bz2
Add FilePath::FinalExtension() to avoid double extensions (.tar.gz) for file selector
Windows and OS X file selectors break badly on double-extensions. GTK and Chrome OS handle it slightly better, but CrOS has a slight bug and GTK's handling of file extensions is minimal, so not a whole lot changed. See https://codereview.chromium.org/4883003/#msg14 for full analysis of platform behavior. There is some logic that does benefit from long extensions (renaming "foo.tar.gz" to "foo (1).tar.gz" instead of "foo.tar (1).gz"), and some other callers store state based on extension, so rather than changing FilePath::Extension, add a new FilePath::FinalExtension and change SelectFileDialog callers to use it. Also work around a problem in NSSavePanel when saving "foo.tar.gz" with extensions hidden. TEST=FilePath.Extension, FilePath.Extension2 FilePath.RemoveExtension Enabling "Ask where to save each file before downloading"; saving a tar.gz doesn't result in weird confirmation prompt on OS X, with or without "Show all filename extensions" enabled in Finder. BUG=83084 Review URL: https://codereview.chromium.org/4883003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/files/file_path.h')
-rw-r--r--base/files/file_path.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/base/files/file_path.h b/base/files/file_path.h
index 33beb0b..f4b8ff8 100644
--- a/base/files/file_path.h
+++ b/base/files/file_path.h
@@ -224,18 +224,33 @@ class BASE_EXPORT FilePath {
// Returns ".jpg" for path "C:\pics\jojo.jpg", or an empty string if
// the file has no extension. If non-empty, Extension() will always start
// with precisely one ".". The following code should always work regardless
- // of the value of path.
+ // of the value of path. For common double-extensions like .tar.gz and
+ // .user.js, this method returns the combined extension. For a single
+ // component, use FinalExtension().
// new_path = path.RemoveExtension().value().append(path.Extension());
// ASSERT(new_path == path.value());
// NOTE: this is different from the original file_util implementation which
// returned the extension without a leading "." ("jpg" instead of ".jpg")
StringType Extension() const;
+ // Returns the path's file extension, as in Extension(), but will
+ // never return a double extension.
+ //
+ // TODO(davidben): Check all our extension-sensitive code to see if
+ // we can rename this to Extension() and the other to something like
+ // LongExtension(), defaulting to short extensions and leaving the
+ // long "extensions" to logic like file_util::GetUniquePathNumber().
+ StringType FinalExtension() const;
+
// Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg"
// NOTE: this is slightly different from the similar file_util implementation
// which returned simply 'jojo'.
FilePath RemoveExtension() const WARN_UNUSED_RESULT;
+ // Removes the path's file extension, as in RemoveExtension(), but
+ // ignores double extensions.
+ FilePath RemoveFinalExtension() const WARN_UNUSED_RESULT;
+
// Inserts |suffix| after the file name portion of |path| but before the
// extension. Returns "" if BaseName() == "." or "..".
// Examples: