Revision 5120f3cb trunk/Pithos.Core/FileState.cs

b/trunk/Pithos.Core/FileState.cs
110 110
            
111 111
        }
112 112

  
113
        public static void ChangeRootPath(string oldPath,string newPath)
114
        {
115
            if (String.IsNullOrWhiteSpace(oldPath))
116
                throw new ArgumentNullException("oldPath");
117
            if (!Path.IsPathRooted(oldPath))
118
                throw new ArgumentException("oldPath must be an absolute path", "oldPath");
119
            if (string.IsNullOrWhiteSpace(newPath))
120
                throw new ArgumentNullException("newPath");
121
            if (!Path.IsPathRooted(newPath))
122
                throw new ArgumentException("newPath must be an absolute path", "newPath");
123
            Contract.EndContractBlock();
124

  
125
            //Ensure the paths end with the same character
126
            if (!oldPath.EndsWith("\\"))
127
                oldPath = oldPath + "\\";
128
            if (!newPath.EndsWith("\\"))
129
                newPath = newPath + "\\";
130

  
131
            using (new TransactionScope())
132
            {
133
                Execute((session, instance) =>
134
                            {
135
                                const string hqlUpdate =
136
                                    "update FileState set FilePath = replace(FilePath,:oldPath,:newPath) where FilePath like :oldPath || '%' ";
137
                                var result=session.CreateQuery(hqlUpdate)
138
                                    .SetString("oldPath", oldPath.ToLower())
139
                                    .SetString("newPath", newPath.ToLower())
140
                                    .ExecuteUpdate();
141
                                return null;
142
                            }, null);
143
            }
144
        }
145

  
113 146
        public static Task<FileState> CreateForAsync(string filePath,int blockSize,string algorithm)
114 147
        {
115 148
            if (blockSize <= 0)

Also available in: Unified diff